简体   繁体   English

将用户生成的查询传递给n层应用程序

[英]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对象(PO​​CO),该对象将被发送到我的业务层(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: 我的想法:

  • My life would be easier if my data structure was the same as my objects structure which was also the same as the view's I present my users. 如果我的数据结构与对象结构相同,并且与视图向用户展示的对象结构相同,那么我的生活将会更加轻松。 However my data structure can not be easily mapped to a users view like many of the control providers like to show in their example. 但是,我的数据结构无法像许多控件提供者所喜欢的那样轻松地映射到用户视图。
  • Many of the Grid control providers offer server side functionality but they require one to use their Linq Providers. 许多网格控制提供程序都提供服务器端功能,但它们需要一个才能使用其Linq提供程序。 This would break many elements of my architecture. 这会破坏我的体系结构的许多元素。
  • The Grid controls do generate an expression 'string', which I could pass to my DAL and have it interpret it. Grid控件确实会生成一个表达式“字符串”,我可以将其传递给DAL并对其进行解释。 This however would couple my DAL to this particular control expression string format. 但是,这会将我的DAL耦合到此特定的控制表达式字符串格式。
  • I could create an 'Expression Tree' pass it as a parameter to my DAL. 我可以创建一个“表达式树”,将其作为参数传递给我的DAL。 I would therefore only have to write a DAL interpreter for the expression tree once. 因此,我只需要为表达式树编写一次DAL解释器。 Then for any Grid control I would have to generate to appropriate expression tree to pass it down. 然后,对于任何Grid控件,我都必须生成适当的表达式树以将其传递下来。

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.

相关问题 n层架构中的身份验证和授权 - Authentication and authorisation in an n-tiered architecture 将基于会话的asp.net应用程序移至n层体系结构 - Moving a session based asp.net application to an n-tiered architecture N层父/子面包屑路径-自下而上循环 - N-tiered Parent/Child Breadcrumb Trail - Bottom to Top Loop 使SqlDataReader在n层上保持打开状态 - Keeping the SqlDataReader open across an n-tiered layer 创建一个n层应用程序 - Creating an n tiered application 通过n层应用程序传递用户身份 - Passing User identity through n-tier application 分层体系结构中的实体框架-要遵循的最佳实践? - Entity Framework in a n tiered architecture - Best Practices to follow? 区分用户生成的和我自己的应用程序生成的鼠标移动 - Distinguish between user generated and my own application generated mouse moves 拦截和更改应用程序生成的 sql 查询 - Intercept and alter sql query generated by the Application Identity 3.0 - 如何在分层应用程序中使用 AspNetUsers ID 作为外键 - Identity 3.0 - How to use AspNetUsers ID as Foreign Key in a Tiered Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM