开发者

LINQ subquery "NOT IN" problem

I do not understand why this query fails.

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;

Or this one:

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.Pro开发者_如何学编程ductTagID)
            select tagus ;

Both give me this error:

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.

Can anyone help me?


It seems that the implementation of the QueryProvider you're using isn't complete. I'm not familiar with the QueryProvider you're using, but maybe you can try something like this:

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;

Hope that helps


Try .Any

var qTags = from tagus in _context.ADN_ProductTagsView
            where !tagAux.Any(t=> t== tagus.ProductTagID)
            select tagus ;

btw, did not run the query, so please check the syntax.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜