2010-03-04 80 views
8

我是EF的新手,所以,對於我可能愚蠢的問題抱歉。我沒有任何關係(VS不加載連接,我不能手動添加它,因爲孩子的主鍵使用其父母的派生鍵)的實體。實體框架和Exists子句

實體主
產品
鍵GKey_K,Product_K
字段.....

實體詳細
GenericInformation
鍵GKey_K,GI_K
字段Product_K,.. ..

那麼,我的問題很簡單(我希望也是我的英文!),我如何才能閱讀對GenericInformation有一些參考的產品?

TIA

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

+0

這不是1802286重複,因爲這正在檢索產品,w在這個問題中,它只是檢查單個對象的存在。 – Rory 2011-01-12 20:03:13

回答

24

在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;