实体框架和Exists子句

Enr*_*ico 9 .net linq entity-framework

我是EF的新秀,对不起我的愚蠢问题.

我有2个没有任何关系的实体(VS不加载连接,我不能手动添加它,因为子主键使用其父项的派生键).

实体主
产品
密钥GKey_K,Product_K
字段.....

实体细节
GenericInformation
键GKey_K,GI_K
字段Product_K,....

好吧,我的问题很简单(我希望也是我的英文!),我怎么才能阅读那些对GenericInformation有一些参考的产品?

TIA

可能重复:
检查实体框架中是否存在对象的最佳方法?

Cra*_*ntz 27

EXISTSin SQL~ = Anyin 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;
Run Code Online (Sandbox Code Playgroud)