[英]Passing a user generated query down an n-tiered application
In my application I use my Data Access Layer (DAL) to generate Plan Old CLR Objects (POCO's) which get sent to my Business Layer (BL). 在我的应用程序中,我使用数据访问层(DAL)生成计划旧CLR对象(POCO),该对象将被发送到我的业务层(BL)。 The BL then uses Model View ViewModel (MVVM) pattern to create object to bind to my Presentation Layer (PL).
然后,BL使用模型视图ViewModel(MVVM)模式创建对象以绑定到我的表示层(PL)。
I want to give my user the ability to filter data on the column level. 我想让我的用户能够在列级别过滤数据。 For example http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/filtering/defaultcs.aspx
例如http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/filtering/defaultcs.aspx
There are other grid controls that perform similar function but generally speaking this is the user experience I want to provide. 还有其他执行类似功能的网格控件,但总的来说,这就是我要提供的用户体验。
I have a large dataset so I want to do all the Paging/Sorting/Filtering on the server side. 我有一个很大的数据集,所以我想在服务器端进行所有的分页/排序/过滤。
It is trivial to send Paging/Sorting data down the n-tiered architecture to my DAL so I would only pull the records I am interested in. 将分页/排序数据沿n层体系结构发送到我的DAL是微不足道的,因此我只提取我感兴趣的记录。
I am however not sure how to send Filter data to my DAL, as a user can generate an arbitrarily long filter expression. 但是,我不确定如何将筛选器数据发送到我的DAL,因为用户可以生成任意长的筛选器表达式。
My Question is: What are my options for sending user generated filter expression through my n-tired application. 我的问题是: 通过n累累的应用程序发送用户生成的过滤器表达式的方法是什么?
My Thoughts: 我的想法:
Just an opinion, but I would avoid the parsing at any cost. 只是一个意见,但我会不惜一切代价避免进行解析。 I would also encourage strongly typed data whenever possible.
我也会尽可能鼓励使用强类型数据。
I'd go with the 'Expression Tree' idea myself. 我本人会接受“表达式树”的想法。 I've used this in large applications without much issue.
我已经在大型应用程序中使用了它,没有太大的问题。 We built our own implementation to represent the expression since we were on .Net 2.0 and didn't need a lot of support (equality only).
由于我们使用的是.Net 2.0,因此我们构建了自己的实现来表示表达式,并且不需要太多的支持(仅用于平等)。 I can't tell from your post if your considering building your own, but we came up with something like the following:
我无法从您的帖子中得知您是否考虑自己构建,但我们提出了以下内容:
class ValueTriple {
System.Type FieldType;
string Field;
object Value;
}
class AndCritieria {
ValueTriple[] Criteria;
}
class OrCriteria {
AndCriteria[] Criteria;
}
We wrapped these classes with rich-type 'query' classes specific to an entity and eventually extended the OrCriteria with sorting/paging information. 我们用特定于实体的丰富类型“查询”类包装了这些类,并最终通过排序/分页信息扩展了OrCriteria。 The query structure above gave us the ability to express any equality based condition regardless of complexity by essentially normalizing the input query structure.
上面的查询结构使我们能够通过本质上标准化输入查询结构来表达任何基于等式的条件,而无需考虑复杂性。 For instance:
例如:
WHERE x = '1' AND (y = '2' OR z = '3')
can also be represented as: 也可以表示为:
WHERE (x = '1' AND y = '2') OR (x = '1' AND z = '3')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.