Many to Many mapping not working - EF 4.1 RC

妖精的绣舞 提交于 2019-12-03 21:45:54
Julie Lerman

You need to specify both navigation properties to do many to many mapping.

Try adding the lambda in the WithMany property pointing back to the products:

this.HasMany(x => x.Categories)
            .WithMany(category=>category.Products)
            .Map(m =>
            {
                m.MapLeftKey(t => t.TagId, "Tag_Id");
                m.MapRightKey(t => t.ProductId, "Product_Id");
                m.ToTable("ProductCategory");
            });

(crossing fingers...)

I haven't used the Code-First approach yet, but when working with POCOs I had to enable Lazy-Loading, to make Navigation Properties work. This is of course by design, but I don't know if you have to explicitly enable this behavior for Code-First.

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