【问题标题】:How convert int to string column? [duplicate]如何将int转换为字符串列? [复制]
【发布时间】:2013-02-07 08:35:50
【问题描述】:

where 表达式:

 filtrationResult = filtrationResult.Where(string.Format("Convert.ToString({0}).Contains(@0)", filter.Field), filter.Value);

filter.Field 是名称列 (Int32)

我得到错误:

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

如何正确转换?

【问题讨论】:

  • 类似于对数字进行部分搜索?

标签: c# sql entity-framework


【解决方案1】:

我会为filter.Field 创建一个包含所有可能值的 switch 语句,然后使用 EF 生成的属性。

【讨论】:

  • 如果你使用的是EF,那么我会使用SqlFunctions.StringConvert
  • “CompanyListItem”类型中不存在属性或字段“SqlFunctions”
  • SqlFunctionsstatic 类。
猜你喜欢
  • 2012-07-04
  • 2011-06-18
  • 2010-09-17
  • 1970-01-01
  • 2013-11-12
  • 2020-12-09
  • 2011-11-26
  • 1970-01-01
  • 2015-06-02
相关资源
最近更新 更多