Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class Parent {
  2. [DatabaseGenerated(DatabaseGeneratedOption.None)]
  3. public Guid Id { get; set; }
  4. public ICollection<Child> Children { get; set; }
  5. }
  6.  
  7. public class Child {
  8. [DatabaseGenerated(DatabaseGeneratedOption.None)]
  9. public Guid Id { get; set; }
  10. public Guid ParentId { get; set; }
  11. }
  12.  
  13. modelBuilder.Entity<Child>().HasKey(c => new { c.Id, c.ParentId });
  14.  
  15. var parent = new Parent() { Id = Guid.NewGuid() };
  16. var child = new Child() { Id = Guid.NewGuid(), ParentId = parent.Id };
  17. parent.Children.Add(child);
  18.  
  19. // Assume parent is already in the DB, with ID of '1b1a6ecd-00ad-4265-ac0d-9a50bd30e247'
  20. INSERT [dbo].[Child]
  21. ([Id],
  22. [ParentId])
  23. VALUES ('1b1a6ecd-00ad-4265-ac0d-9a50bd30e247' /* @0 */,
  24. '1b1a6ecd-00ad-4265-ac0d-9a50bd30e247' /* @1 */)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement