When using the CTP 5 of Entity Framework code-first library (as announced here) I\'m trying to create a class that maps to a very simple hierarchy table.
Here\'s the SQL
It should work using a mapping like below:
class FamilyContext : DbContext
{
public DbSet People { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity().HasMany(x => x.Children).WithMany().Map(y =>
{
y.MapLeftKey((x => x.Id), "ParentID");
y.MapRightKey((x => x.Id), "ChildID");
});
}
}
However that throws an exception: Sequence contains more than one matching element. Apperently that is a bug.
See this thread and the answer to @shichao question: http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-fluent-api-samples.aspx#10102970