我想这短短的SQL语句转换成LINQ,但我面临着一些困难,这是我的最新尝试,显然他有一个错误:Linq查询帮助
SQL:
select ProductID from products where
categoryID in (select categoryID from categories_sub
where categoryID='15' and category_sub_name = 'chiffon')
的Linq:
'15' 和 '薄纱' 由参数取代 'CID' 和 'subCatID' 在这里:
IQueryable<Categories_Sub > cat = (from c in db.Categories_Sub
where c.CategoryID == cID
& c.Category_Sub_ID == subCatID
select c);
var subcat = (from c in db.Products
where cat.Contains(c.ProductID)
select c);
Linq to SQL or Entity Framework?什么样的错误? –
咦?您看起来像是在SQL查询中选择了categoryID == 15的所有产品。这是正确的吗?你想达到什么目的? – musefan
当您稍后通过等于'15'来过滤它时,选择'categoryID'有什么意义? –