我有代码从数据库中获取id列表。该代码是使用LINQ低于如何使用LINQ选择更大的ID到SQL
var resutls = (from v in con.NewsLatter
where v.SendStatus == "Active"
select new { v.Id }).ToList;
它从表名为NewsLater的数据库返回一个所有ID。现在,我想要做的就是填补这一切ID在
List<Int32> IdList = new List<Int32>{ //list of id want to fill here in List<Int32> };
var min = IdList .Where(x=>x>12).Min();
return min;
当我试图填补这一这样下面
List<Int32> IdList = new List<Int32> { Convert.ToInt32(resutls) };
var min = IdList .Where(x => x > 12).Min();
return min;
我有一个例外:
Unable to cast object of type
'System.Collections.Generic.List`1[<>f__AnonymousType0`1[System.Int32]]' to type
'System.IConvertible'.
任何人有什么想法这里有什么问题吗?
GOT 2错误其下面: 错误\t \t 1为“System.Collections.Generic.List .AddRange最好重载的方法匹配(System.Collections.Generic.IEnumerable )'有一些无效参数 和 错误参数1:无法从'System.Collections.Generic.List '转换为'System.Collections.Generic.IEnumerable ' –
它将抛出错误1无法将方法组分配给隐式类型的局部变量 –
我改变了我的代码,因为我错过了ToList()旁边的括号。请再次尝试我的代码。它会工作,我刚刚在我的PC上的一个控制台应用程序中尝试了它。 –