LINQ to Entities无法识别方法'System.String Format [英] LINQ to Entities does not recognize the method 'System.String Format

查看:55
本文介绍了LINQ to Entities无法识别方法'System.String Format的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何重构此LINQ才能使其正常工作?

How can i refactor this LINQ to make this work?

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 Format(System.String,System.Object,System.Object)'方法,以及此方法 方法不能转换为商店表达式.

LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)' method, and this method cannot be translated into a store expression.

我没有做过尝试:

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();

推荐答案

您可以在LINQ-to-Objects中返回string.Format:

You can do the string.Format back in LINQ-to-Objects:

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();

这篇关于LINQ to Entities无法识别方法'System.String Format的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆