如何在 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 子句 Linq
int[] productList = new int[] { 1, 2, 3, 4 };
var myProducts = from p in db.Products
where productList.Contains(p.ProductID)
select p;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)