gpt4 book ai didi

c# - Linq 中的 Sql IN 子句等效

转载 作者:行者123 更新时间:2023-12-02 10:46:50 25 4
gpt4 key购买 nike

我想在 linq 的 cluase 中使用 sql,因为我尝试过包含但它显示错误。我的代码是..

 var allId = new int[] { 31, 32, 33 };
var libraryList = from c in db.COURSELIBRARies
join cc in db.COURSECATEGORYTAGGINGs on c.LIBITEMID equals cc.COURSEID
where allId.Contains(cc.CATEGORYID) // here error is showing.
select new Library { Id = c.LIBITEMID, Name = c.GROUPNAME, Desc = c.DESCRIPTION, logo = c.LOGO, CategoryId = cc.CATEGORYID };
错误是:

'int[]' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.Queryable.Contains<TSource>(System.Linq.IQueryable<TSource>, TSource)' has some invalid arguments

Instance argument: cannot convert from 'int[]' to 'System.Linq.IQueryable<int?>'

最佳答案

你包括了吗?

using System.Linq;

?

另一个可能的原因是您传递给 Contains() 的值不是 INT。尝试转换: where allId.Contains((int)cc.CATEGORYID)

关于c# - Linq 中的 Sql IN 子句等效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28470304/

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