实体框架和Exists子句

时间:2010-03-04 12:24:44

标签: .net linq entity-framework

我是EF的新手,对不起我的愚蠢问题。

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

实施例

实体主人
产品
键GKey_K,Product_K
田野.....

实体详情
GenericInformation
键GKey_K,GI_K
字段Product_K,....

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

TIA

  

可能重复:
   Best way to check if object exists in Entity Framework?

1 个答案:

答案 0 :(得分:26)

SQL中的

EXISTS〜= Any在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;