Problem with LINQ subquery "NOT IN"

.net .net-3.5 c# entity-framework linq

Question

I'm not sure why this query is unsuccessful.

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 maybe this:

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 ;

I get this problem from both:

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 somebody assist me?

1
4
5/10/2011 6:42:30 PM

Accepted Answer

It seems that the QueryProvider you're using doesn't have a full implementation. Though I don't know much about the QueryProvider you're using, maybe you could try something similar:

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's helpful.

5
5/10/2011 5:08:36 PM

Popular Answer

Any try

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

By the way, the query was not performed, so double-check the syntax.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow