两个简单的查询 - 异常发生在:
matchings.Any(u => product.ProductId == u.ProductId)
怎么了?如果我写true
相反,一切都很好。
var matchings = (from match in db.matchings
where match.StoreId == StoreId
select match).ToList();
var names = (from product in db.Products
where matchings.Any(u => product.ProductId == u.ProductId)
select product).ToList();
第一种方式:
Remove ToList()
在第一个查询中。
Or
//instead of retrieving mathings List, retrieve only the productIds you need (which are a List of Primitive types)
var productIdList = db.matchings
.Where(m => m.StoreId == StoreId)
.Select(x => x.ProductId)
.ToList();
var products = db.Products
.Where(p => productIdList
.Contains(p.ProductId))
.ToList();
Or
//other way
var produts = db.Products
.Where(p => db.matchings
.Any(m => m.StoreId == StoreId &&
m.ProductId == p.ProductId)
)
.ToList();
因为我认为你在 linq2entities 中,并且你在查询中使用匹配列表,这是不可能的(你的主题的标题往往让我相信这是你的问题)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)