用户搜索屏幕的Linq动态查询 [英] Linq dynamic queries for user search screens

查看:53
本文介绍了用户搜索屏幕的Linq动态查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,该数据库的用户搜索屏幕是动态的",可以根据正在搜索的特定视图中的可用列动态添加其他搜索条件,并允许用户立即使用它们.以前我一直在使用nettiers来存储该数据库,但是现在我正在使用RIA和EntFramework 4和LINQ针对它编写一个新的应用程序.

I have a database that has a user search screen that is "dynamic" in that I can add additional search criteria on the fly based on what columns are available in the particular view the search is based on and it will allow the user to use them immediately. Previously I had been using nettiers for this database, but now I am programming a new application against it using RIA and EntFramework 4 and LINQ.

我目前有2个用于此目的的表,其中一个表用可用的搜索字符串模式填充了组合框:

I currently have 2 tables that are used for this, one that fills the combobox with the available search string patterns:

姓氏 姓氏,名字 电话 等等.

LastName LastName, FirstName Phone etc....

然后,我还有另一个表将这些条件分解出来,并用在我的nettiers算法中.它运行良好,但我想使用LINQ ..并且它与该模型不太匹配.此外,我认为我可以使用linq将其缩减为一张桌子...

then I have an other table that splits those criteria out and is used in my nettiers algorithms. It works well, but I want to use LINQ..and it doesnt fit this model very well. Besides I think I can pare it down to just one table with linq...

使用与此类似的格式或非常接近的格式...

using a format similar to this or something very close...

ID条件在哪里 1个姓氏'姓氏,如'%{0}%'

ID Criteria WhereClause 1 LastName 'Lastname Like '%{0}%'

现在我知道这不会特别适合linq查询..但是为了清楚起见,我正在尝试使用统一语法...

now I know this wont fit specifically into a linq query..but I am trying to use a univeral syntax for clarity here...

真正的where子句看起来像这样:a => a.LastName.Contains("{0}")

the real where clause would look something like this: a=>a.LastName.Contains("{0}")

我的第一个问题是:那有可能做到吗?将lambda输入到字符串中,并在Linq查询中使用它?

My first question is: Is that even possible to do? Feed a lambda in to a string and use it in a Linq Query?

我的第二个问题是:在研究此问题的某个时候,我发现了具有这样前缀的linq语法.LastName{0} 我似乎已尝试使用它,因为它的痕迹仍在我的测试数据库中...但是我不知道我在哪里读到它.

My second question is: at one point when I was researching this before I found a linq syntax that had a prefix like it.LastName{0} and I appear to have tried using it because vestiges of it are still in my test databases...but I dont know recall where I read about it.

有人这样做吗?我进行了一些搜索并发现了类似的情况,但是它们中的大多数静态字段是可选的,而不完全是我的操作方式...

Is anyone doing this? I have done some searches and found similar occurances but they mostly have static fields that are optional, not exactly the way I am doing it...

推荐答案

对于第一个问题,您可以按照Scott Gu

As for your first question, you can do this using Dynamic Linq as described by Scott Gu here

var query = Northwind.Products.Where("Lastname LIKE "test%");

这篇关于用户搜索屏幕的Linq动态查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆