gpt4 book ai didi

c# - LINQ子查询 "NOT IN"问题

转载 作者:太空狗 更新时间:2023-10-30 00:45:15 29 4
gpt4 key购买 nike

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

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,但也许您可以尝试这样的操作:

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;

希望对你有帮助

关于c# - LINQ子查询 "NOT IN"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5953634/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com