LINQ subquery "NOT IN"

I do not understand why this request 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.ProductTagID)
            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 anybody help me?

+3
source share
2 answers

It seems that the QueryProvider implementation you are using is not complete. I am not familiar with the QueryProvider you are 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

+4
source

Give it a try. Any

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

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

+2
source

All Articles