Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework and Exists clause

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?

like image 796
Enrico Avatar asked Mar 04 '10 12:03

Enrico


1 Answers

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;
like image 113
Craig Stuntz Avatar answered Oct 05 '22 21:10

Craig Stuntz