我如何重构这个LINQ以使其工作?
var a = (from app in mamDB.Apps where app.IsDeleted == false
select string.Format("{0}{1}",app.AppName,
app.AppsData.IsExperimental? " (exp)": string.Empty))
.ToArray();}
我现在收到错误:
LINQ to Entities无法识别方法'System.String 格式化(System.String,System.Object,System.Object)'方法,以及此方法 方法无法转换为商店表达式。
我无用地尝试过:
return (from app in mamDB.Apps where app.IsDeleted == false
select new string(app.AppName + (app.AppsData != null &&
app.AppsData.IsExperimental)? " (exp)": string.Empty)).ToArray();
答案 0 :(得分:17)
您可以在LINQ-to-Objects中执行string.Format
:
var a = (from app in mamDB.Apps where app.IsDeleted == false
select new {app.AppName, app.AppsData.IsExperimental})
.AsEnumerable()
.Select(row => string.Format("{0}{1}",
row.AppName, row.IsExperimental ? " (exp)" : "")).ToArray();
答案 1 :(得分:0)
试试这个
var a = (from app in mamDB.Apps where app.IsDeleted == false
select new {AppName = app.AppName, IsExperimental = app.AppsData.IsExperimental})
.Select(app => string.Format("{0}{1}",app.AppName,
app.IsExperimental? " (exp)": string.Empty))
.ToArray();}