我不明白为什么这个查询失败了。
var qTags = from tagsU in _context.ADN_ProductTagsView
where !(from o in _context.ADN_ProductTagsView
where o.ProductID == productId
select o.ProductTagID).Contains(tagsU.ProductTagID)
select tagsU;
或者这个:
var tagAux = from o in _context.ADN_ProductTagsView
where o.ProductID == productId
select o.ProductTagID;
var qTags = from tagus in _context.ADN_ProductTagsView
where !tagAux.Contains(tagus.ProductTagID)
select tagus ;
两个都给我这个错误:
LINQ to Entities does not recognize the method 'Boolean Contains[Int32](System.Linq.IQueryable`1[System.Int32], Int32)' method, and this method cannot be translated into a store expression.
任何人都可以帮助我吗?
答案 0 :(得分:4)
您正在使用的QueryProvider的实现似乎并不完整。我不熟悉您正在使用的QueryProvider,但也许您可以尝试这样的事情:
var qTags = from tagsU in _context.ADN_ProductTagsView
where !(from o in _context.ADN_ProductTagsView
where o.ProductID == productId
select o.ProductTagID).Any(tagId => tagId == tagsU.ProductTagID)
select tagsU;
希望有所帮助
答案 1 :(得分:2)
尝试.Any
var qTags = from tagus in _context.ADN_ProductTagsView
where !tagAux.Any(t=> t== tagus.ProductTagID)
select tagus ;
btw,没有运行查询,所以请检查语法。