【问题标题】:Convert field in linq query c# [duplicate]在linq查询c#中转换字段[重复]
【发布时间】:2016-10-28 14:43:36
【问题描述】:

我有一个查询,我想将十进制字段转换为字符串,但查询返回上述错误

LINQ to Entities does not recognize the method 'System.String ToString () "and it can not be translated into term store.

我的查询:

    var t = (from f in db.teacher_fee
             where f.fee_status == 1
             select new
             {
                 f.fee_date,
                 f.teacher_fee_id,
                 debit = "",
                 credit = f.total_amount.ToString()
             }); 

有人可以帮我吗 谢谢

【问题讨论】:

标签: c# asp.net sql-server asp.net-mvc linq


【解决方案1】:

您不能将(在您的示例中为 System.ToString())之类的方法应用于不在内存中的内容。

所以基本上,查询从未执行过。如果你看它,这仍然是一个 IQueryable。

在将方法应用到您的字段之前,您需要将其与 AsEnumerable() 或 ToList() 一起使用。

【讨论】:

  • 谢谢我现在看到了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
  • 2012-05-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多