如何在 linq 中编写下面的 sql 查询
select * from Product where ProductTypePartyID IN
(
select Id from ProductTypeParty where PartyId = 34
)
最佳答案
LINQ 中没有直接的等效项。相反,您可以使用 contains () 或任何
其他实现它们的技巧。下面是一个使用 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;
查看此链接了解详细信息: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;
关于sql-server - SQL 的 "IN"关键字的 LINQ 等价物是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8255205/