我试图在Linq中使用Entity Framework转换旧的原始Sql查询.
它使用IN运算符和一组项目.查询是这样的:
SELECT Members.Name
FROM Members
WHERE Members.ID IN ( SELECT DISTINCT ManufacturerID FROM Products WHERE Active = 1)
ORDER BY Members.Name ASC
Run Code Online (Sandbox Code Playgroud)
由于子查询的返回不是单个字符串而是字符串集合,因此我无法使用该String.Contains()方法.
我想过做的事情:
var activeProducts = (
from products in db.ProductSet
where product.Active == true
select product.ManufacturerID);
Run Code Online (Sandbox Code Playgroud)
然后
var activeMembers = (
from member in db.ContactSet
where member.ID.ToString().Contains(activeProducts));
Run Code Online (Sandbox Code Playgroud)
但它停止在包含说它有无效的参数...我不能选择activeProducts.ManufacturerID,因为很明显,proprety不存在,因为它返回IQueryable ...
我在这里要做的就是返回一个至少有一个活跃产品的成员列表.
任何提示?
[编辑]
这是完整的查询代码......我尝试使用第二个表达式的包含,Linq似乎不喜欢它:
Server Error in '/' Application.
LINQ to Entities does not recognize the method 'Boolean Contains[String](System.Linq.IQueryable``1[System.String], System.String)' method, and this method cannot …