Entity framework and Exists clause

只愿长相守 提交于 2020-01-11 08:11:07

问题


I'm a rookies of EF so, sorry for my perhaps foolish question.

I've 2 entities without any relationship (VS does not load the join and I can't manually add it because the primary key of the child uses a derivated key of its parent).

Example

Entity master
Products
keys GKey_K, Product_K
fields .....

Entity detail
GenericInformation
keys GKey_K, GI_K
fields Product_K, ....

Well, my question is simple (I hope also my english!), how I can read only the products that have some reference on GenericInformation?

TIA

Possible duplicate:
Best way to check if object exists in Entity Framework?


回答1:


EXISTS in SQL ~= Any in LINQ:

var q = from p in Context.Products
        where Context.GenericInformation.Any(gi => gi.Product_K == p.Product_K)
        // add other columns to the where if need be; I can't tell what the 
        // relationship is supposed to be
        select p;


来源:https://stackoverflow.com/questions/2379183/entity-framework-and-exists-clause

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