LINQ子查询"NOT IN"问题 [英] LINQ subquery "NOT IN" problem

查看:55
本文介绍了LINQ子查询"NOT IN"问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么这个查询失败.

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;

或者这个:

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.

有人可以帮助我吗?

推荐答案

您正在使用的QueryProvider的实现似乎还不完整.我对您使用的QueryProvider不熟悉,但是也许您可以尝试这样的事情:

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;

希望有帮助

这篇关于LINQ子查询"NOT IN"问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆