在linq中将int转换为字符串以进行搜索 [英] convert int to string in linq for searching
本文介绍了在linq中将int转换为字符串以进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的用户能够通过部分字符串搜索采购订单(即INT),即如果采购订单为123456,则输入456会给我123456的结果.
I would like my users to be able to search for purchase orders (which are INT's) via partial strings, i.e. if a purchase order is 123456 typing in 456 gives me 123456 in the results.
我认为这会起作用:
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转换为字符串以使我能够搜索它的片段?
How can I convert the INT PurchaseOrderID to a string to enable me to search for fragments of it?
谢谢
推荐答案
供以后参考,请使用以下方法解决此问题:
For future reference, have fixed this by using:
var pop = ctx
.PurchaseOrders
.OrderBy(x => x.PurchaseOrderID)
.ToList()
.Select(x => new SearchItem()
{
id = x.PurchaseOrderID.ToString(),
label = x.SupplierID,
category = "purchaseorder"
});
使它起作用的是中介列表.
It's the intermediary list that makes it work.
这篇关于在linq中将int转换为字符串以进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文