我希望用户能够通过部分字符串搜索采购订单(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.
我该如何将整数类型的PurchaseOrderID转换为字符串类型,以便于我可以搜索其中的片段?
谢谢!
let poid = (string)po.PurchaseOrderID
。Linq to entities 会遵循某些方法调用,但ToString
不在其范围内。直接转换在逻辑上相当于 SQL 中的CAST(X as Type)
。 - Simon Belanger