自动完成扩展器“扩展”跨整个数据表
我请求创建一个自动完成功能来搜索数据表。这是否可以快速简单地实现,或者是否需要编写合理数量的代码?
最初,我一直在使用 Web 服务和 linq 来指向单个列的数据值 (IDDesc) 并拉回产品列表:
Product.FinalProductsDataContext dbac = new Product.FinalProductsDataContext();
return dbac.tblProduct
.Where(r => r.Account== HttpContext.Current.Session["AccountKey"].ToString() && r.IDDesc.Contains(prefixText))
.Distinct()
.OrderBy(r => r.IDDesc)
.Select(r => r.IDDesc)
.Take(count)
.ToArray();
但是,如果我希望自动完成功能查看所有列,是否会重复对于数据表中包含的每个列是否有类似的 LINQ 语句,或者是否有“快速修复”?
我个人认为这不是一个理想的情况,但这是我必须努力实现的要求。
任何帮助或建议,不胜感激。
I have a request to create an auto complete that will search an data table. Is this achieveable quickly and simply or is it a case of writing a reasonable amount of code?
Originally, I have been using a webservice and linq to point at a single column's worth of data (IDDesc) and pull back the list of products:
Product.FinalProductsDataContext dbac = new Product.FinalProductsDataContext();
return dbac.tblProduct
.Where(r => r.Account== HttpContext.Current.Session["AccountKey"].ToString() && r.IDDesc.Contains(prefixText))
.Distinct()
.OrderBy(r => r.IDDesc)
.Select(r => r.IDDesc)
.Take(count)
.ToArray();
However, if I wish the autocomplete to look at all the columns, is it a case of repeating similar LINQ statements for each of the columns contained within the datatable or is there a 'quick fix'?
I personally don't think this is an ideal scenario but it is a request I must work towards.
Any help or advice, greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为我应该在数据库中放入一些内容,而不是尝试使用 LINQ 来完全解决这个问题(并对表中的每一列重复所有这些语句,以及重复访问数据库)在这里做繁重的工作。
您可以创建一个视图,该视图从表中获取字段并将它们合并到一列中,例如,
如果您将视图添加到上下文中,则将允许您修改现有的 LINQ 查询并将其指向该视图,例如:
Rather than trying to solve this entirely with LINQ (and repeating all those statements for each column in the table, as well as hitting the database repeatedly), I think I'd look to put something in the database to do the heavy lifting here.
You could create a view that takes the fields from the table and amalgamates them into one column e.g.
which if you added the view to your context would then allow you to modify your existing LINQ query and point it at that view e.g.: