How can I write below sql query in linq
select * from Product where ProductTypePartyID IN
(
select Id from ProductTypeParty where PartyId = 34
)
<
There is no direct equivalent in LINQ. Instead you can use contains () or any
other trick to implement them. Here's an example that uses Contains
:
String [] s = new String [5];
s [0] = "34";
s [1] = "12";
s [2] = "55";
s [3] = "4";
s [4] = "61";
var result = from d in context.TableName
where s.Contains (d.fieldname)
select d;
check this link for details: in clause Linq
int[] productList = new int[] { 1, 2, 3, 4 };
var myProducts = from p in db.Products
where productList.Contains(p.ProductID)
select p;