Entity Framework 4 CTP 5 Self Referencing Many-to-Many

巧了我就是萌 提交于 2019-11-28 23:54:03

This is what I have in an EntityTypeConfiguration<> implementation for a similar situation in CTP5.

HasMany(g => g.SubGroups)
    .WithMany(g => g.ParentGroups)
    .Map(m => m.ToTable("Groups_SubGroups"));

Not sure exactly how that translates to configuring the DbContext directly, but I imagine it should be close.

If memory serves, LeftKey() RightKey() syntax wasn't quite there in CTP5, so you just have to use the default column names that it creates or is expecting. In my case, it is GroupId and GroupId1. That follows the pattern <class>Id and <class>Id1, not <field> and <field>1 by the way.

The error that you're getting does seem familiar and I don't remember that the solution was obvious in any way. But, I did set this all up a while ago so the memories of how I arrived at something that works is a bit swiss cheesed. Hope it helps some.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!