实体框架ToString方法 [英] Entity Framework ToString method

查看:135
本文介绍了实体框架ToString方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码块引发错误。


LINQ to Entities不识别方法System.String ToString此方法无法转换为商店表达式。

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



db.tbOnIgmHawbDetails
  .Where(s => !db.tbImpoExaminations.Any(x => x.Hawb.ToString() == s.Hawb) && s.AwbNo == p)
  .Select(s => s.Hawb).ToList();

有任何建议吗?为什么会发生这种情况,解决方案是什么?

Any suggestion? why this happen and what is the solution?

推荐答案

您可以尝试使用 SqlFunctions.StringConvert ...使用十进制转换:

You could try with SqlFunctions.StringConvert... Use the decimal conversion:

SqlFunctions.StringConvert((decimal)p.x.Hawb).TrimLeft() == ...

code> TrimLeft 是必要的,因为SQL的 STR 函数将使数字对齐)

(the TrimLeft is necessary because the STR function of SQL will right align the number)

这篇关于实体框架ToString方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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