C# “LINQ子查询”;不在「;问题
我不明白为什么这个查询失败C# “LINQ子查询”;不在「;问题,c#,.net,linq,entity-framework,.net-3.5,C#,.net,Linq,Entity Framework,.net 3.5,我不明白为什么这个查询失败 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 =
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.
有人能帮我吗?试试。有人吗
var qTags = from tagus in _context.ADN_ProductTagsView
where !tagAux.Any(t=> t== tagus.ProductTagID)
select tagus ;
顺便说一句,没有运行查询,所以请检查语法 您正在使用的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;
希望这对.NET3.5下的EF有所帮助,真是糟透了。移动到.NET4.0,您的问题就会消失。EF一般来说很糟糕,但他不需要升级来解决此问题。