积极答复者
EF DBFirst方式多对多联合主键如何进行联查

问题
答案
-
Hi momoxiao,
感谢您的反馈。
根据我的搜索以及研究,暂时还没有找到方法来直接联查三张表。
我建议你手动创建中间表类,然后从数据库获取相关数据,填充一个新的list,最后再用linq查询,这样的话就可以联查三张表了。
Best Regards,
Jack
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 momoxiao 2020年11月27日 8:13
全部回复
-
Hi momoxiao,
根据我的测试,我重现了你的问题,我建议你可以参照下面的方法来联合查询三张表。
首先,你需要在你的中间表中加一个字段,重新Dbfurst之后,就会出现三张表。
其次,你可以采用下面的linq语句来查询三张表。
using (var context = new BloggingContext()) { // Query for all blogs with names starting with B var blogs = from c in context.categories from m in context.movies from t in context.movie_category_junction where c.category_id == t.category_id && m.movie_id == t.movie_id select c; // Query for the Blog named ADO.NET Blog }
希望可以帮到你。
Best Regards,
Jack
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
Hi momoxiao,
感谢您的反馈。
根据我的搜索以及研究,暂时还没有找到方法来直接联查三张表。
我建议你手动创建中间表类,然后从数据库获取相关数据,填充一个新的list,最后再用linq查询,这样的话就可以联查三张表了。
Best Regards,
Jack
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 momoxiao 2020年11月27日 8:13