LINQ子查询“ NOT IN”问题

Her*_*cko 4 .net c# 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;
Run Code Online (Sandbox Code Playgroud)

或者这个:

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 ;
Run Code Online (Sandbox Code Playgroud)

两者都给我这个错误:

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.
Run Code Online (Sandbox Code Playgroud)

谁能帮我?

Fed*_*ede 5

您正在使用的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;
Run Code Online (Sandbox Code Playgroud)

希望能有所帮助