LINQ to Entities 无法识别方法“System.String ToString()”方法,并且此方法无法转
本文关键字:方法 此方法 String Entities to 识别 LINQ System ToString | 更新日期: 2023-09-27 18:30:24
当我尝试运行以下代码时。
var result = from c in db.brand
where c.title.contains("test")
select c.title + "-" +c.brand;
List<string> lst = r.ToList();
它给出了以下错误。
LINQ to Entities 无法识别方法"System.String ToString()' 方法,并且此方法无法转换为存储 表达。
我建议以匿名类型获取标题和品牌,然后在进程中执行字符串连接:
var list = db.Brand.Where(c => c.Title.Contains("test"))
.Select(c => new { c.Title, c.Brand })
.AsEnumerable() // Rest of the query in-process
.Select(x => x.Title + " " + x.Brand)
.ToList();
试试这个:
var result = from c in db.brand where c.title.contains("test") select c;
var finalResult = result.ToList().Select(ss=> ss.title + "-" + ss.brand);
尝试:
var result = from c in db.brand where c.title.contains("test") select new { c.title + "-" +c.brand }