daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. create table Entities(
  2.     EntityId bigint not null identity(1, 1),
  3.     Name nvarchar(64) not null,
  4.     ParentEntityId bigint null
  5. )
  6. alter table Entities add constraint PK primary key (EntityId)
  7. alter table Entities add constraint FK foreign key (ParentEntityId) references Entities(EntityId)
  8.    
  9. public class Entity
  10. {
  11.     [Required]
  12.     public virtual long EntityId { get; set; }
  13.  
  14.     [Required]
  15.     public virtual string Name { get; set; }
  16.  
  17.     public virtual long? ParentEntityId { get; set; }
  18.  
  19.     public virtual Entity ParentEntity { get; set; }
  20. }
  21.    
  22. modelBuilder.Entity<Entity>()
  23.             .HasOptional(e => e.ParentEntity)
  24.             .WithMany()
  25.             .HasForeignKey(e => e.ParentEntityId );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top