类别ID
var itms = from item in CMP.tblItems
let t2s = (from g in CMP.tblProducts
where g.CategoryID==CatID
select g.ProductID)
where item.Name.Contains(Model) && item.ProductID.ToString() == t2s.ToString()
select new { item.Name };
我的问题是多个产品返回到t2s(子查询)。如果我将FirstOrDefault()添加到Sub-Query,那么它将只与一个产品ID匹配!我需要匹配它返回的所有产品。
答案 0 :(得分:1)
试试这个:
var itms=from item in CMP.tblItems
from g in CMP.tblProducts
where item.Name.Contains(Model) && item.ProductID == g.ProductID && g.CategoryID == CatID
select new {item.Name};
答案 1 :(得分:0)
使用LINQ-to-SQL为您创建的导航属性。 Item
应该拥有属性Product
。所以你可以这样做:
var itms = from item in CMP.tblItems
where item.Name.Contains(Model) && item.Product.CategoryID = CatId
select new { item.Name };