【发布时间】:2014-01-21 11:48:41
【问题描述】:
我希望我的用户能够通过部分字符串搜索采购订单(即 INT),即如果采购订单是 123456,输入 456 会在结果中给我 123456。
我认为这会起作用:
var pop = (from po in ctx.PurchaseOrders
let poid = po.PurchaseOrderID.ToString()
where poid.Contains(term)
select new SearchItem
{
id = poid,
label = po.SupplierID,
category = "purchaseorder"
}).ToList();
但我得到一个错误
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
如何将 INT PurchaseOrderID 转换为字符串,以便搜索其中的片段?
谢谢
【问题讨论】:
-
尝试直接转换,即
let poid = (string)po.PurchaseOrderID。 Linq to 实体将尊重某些方法调用,ToString不是其中之一。直接强制转换在逻辑上等同于 SQL 中的CAST(X as Type)。 -
我在这里回答了类似的问题。看看这个。 stackoverflow.com/questions/21233023/…
-
您的问题的解决方案在这里:stackoverflow.com/questions/1066760/…
标签: c# asp.net linq entity-framework