加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – EF5.x中对PadLeft缺乏支持的任何解决方法?

发布时间:2020-12-16 07:05:25 所属栏目:asp.Net 来源:网络整理
导读:我正在研究MVC4和Entity Framework 5中的应用程序,最近在执行查询时遇到了这个异常. {“LINQ to Entities does not recognize the method ‘System.String PadLeft(Int32,Char)’ method,and this method cannot be translated into a store expression.”}
我正在研究MVC4和Entity Framework 5中的应用程序,最近在执行查询时遇到了这个异常.

{“LINQ to Entities does not recognize the method ‘System.String PadLeft(Int32,Char)’ method,and this method cannot be translated into a store expression.”}

当我在过去遇到过类似的错误时,我只是在查询之外创建了一个变量,然后在LINQ语句中使用了该变量.不幸的是,在这种情况下,我正在操纵行结果,所以我不确定如何去做或如果这是最好的方法.任何帮助,将不胜感激.我的查询如下:

IQueryable<System.String> LEAPrograms = db.Datamart_Draft
            .Where(where => where.snapshot_id == snapshot_id
                && !String.IsNullOrEmpty(where.entity_program))
            .Select(sel => (sel.entity_program.PadLeft(PROGRAMLENGTH,'0'))).Distinct();

解决方法

这不是太优雅,但它做的工作:

...
.Select(sel => SqlFunctions.Replicate
                   ("0",PROGRAMLENGTH - sel.entity_program.Length)
             + sel.entity_program)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读