Guest User

Untitled

a guest
Jan 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  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 );
Add Comment
Please, Sign In to add comment