Relationship on same table with Entity Framework
c#, entity-framework, entity-framework-4, entity-relationship
Solution
I think the following shall do it:
modelBuilder.Entity<Item>()
.HasOptional(c => c.ChildItems)
.WithMany()
.HasForeignKey(c => c.ThreadId);
Problem
How can I specify a realtionship on the same table using Entity Framework? My table 'Items' has the following fields: - Id (uniqueidentifier) - ThreadId (uniqueidentifier) - Created (datetime) - Text (nvarchar(max)) My model 'Item': - Id (Guid) - ThreadId (Guid) - Created (DateTime) - Text (string) - ChildItems (Icollection) How can I create the relationship so that ChildItems holds the items with Id = ThreadId?