c# - 如何解决 LINQ to Entities 无法识别方法 'System.String ToString()' 方法?

标签 c# linq

我已经检查了与此相关的所有示例,但未能解决我的问题。

我已经创建了复选框,如果我以前不选中就意味着获取一些值

返回

string selectedid = {"2","6","45","34","5"};  
string[] separteid = Regex.Split(selectedid, ",");

List<string>idlist=new List<string>();
foreach(var item in separteid)
{
     idlist.Add(item);
}   

我想检查数据库表的整数ID

job = (from n in bc.db.xx where idlist.Contains(n.id.ToString()) select n);
ViewBag.Count = job.Count(); 

如何解决?有人帮忙吗?

最佳答案

如果使用的 EF 版本为 4 或以上,则可以使用以下内容。检查this了解更多。

SqlFunctions.StringConvert((Decimal)n.id).Trim(),

否则,您可以将字符串列表转换为如下所示的 int 列表,然后使用 .Contains 覆盖它。

job = (from n in bc.db.xx where idlist.Select(x=>int.Parse(x)).Contains(n.id) select n);

关于c# - 如何解决 LINQ to Entities 无法识别方法 'System.String ToString()' 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34715591/

相关文章:

c# - Xml 反序列化和默认值

c# - RSA 在 C# (.NET 3.5) 中解密数据,在 php 5.3.2 中用 openssl 加密

c# - 有没有办法使用 LINQ 从 List<T> 中删除某些元素?

c# - 为什么 Entity Framework 6 不支持 Discriminator 的显式过滤?

Web API Controller 方法的 LINQ 查询 JOIN 两个表

c# - 如何从 LINQ 获取 ExecuteCommand(或 ExecuteQuery)的字符串值?

c# - 是否有使用属性将注入(inject)参数绑定(bind)到成员字段的包?

c# - 单点触控 : Rounded UIImage Convenience Method

c# - 从包含通用 O​​bservableCollection 的类型 (System.type) 中获取字符串 "System.Collections.ObjectModel.ObservableCollection"?

c# - LINQ 查询需要在同一查询中升序或降序