简体   繁体   English

实现LINQ提供程序

[英]Implementing LINQ provider

I'm currently implementing a LINQ provider for my own educational purposes. 我目前正在为自己的教育目的实施LINQ提供程序。 I have managed to get Count() extension to work recently, so far so good. 我最近设法让Count()扩展工作,到目前为止一直很好。

Now my question is not a cry for help, but just a request for some clarification. 现在我的问题不是寻求帮助,而是要求澄清一些。

There are two interfaces to be implemented in order to create the provider: IQueryProvider and something like IOrderedQueryable<> . 要创建提供程序,需要实现两个接口: IQueryProvider和类似IOrderedQueryable<> MSDN makes clear how one implements them, but one point is still confusing me. MSDN明确了如何实现它们,但有一点仍让我感到困惑。

Why these interfaces are implemented by separate classes , even though each IOrderedQueryable instance refers own IQueryProvider instance and both objects actually (indirectly) refer the same data? 为什么这些接口是由单独的类实现的 ,即使每个IOrderedQueryable实例都引用自己的IQueryProvider实例,并且这两个对象实际(间接)引用相同的数据?

Do they really need to be separated? 他们真的需要分开吗?

Furthermore. 此外。 I am able to combine them like this: class Source<RowContract> : IQueryProvider, IOrderedQueryable<RowContract> - in order to simplify type information access. 我可以像下面这样组合它们: class Source<RowContract> : IQueryProvider, IOrderedQueryable<RowContract> - 以简化类型信息访问。 This implementation works properly now and looks more simple and clear than "separate-classes" approach. 此实现现在正常工作,看起来比“单独类”方法更简单明了。

I am wondering if there is a flaw in my combined implementation. 我想知道我的组合实施是否存在缺陷。 Or, maybe it's valid? 或者,也许它有效?

Any explanation would be appreciated greatly. 任何解释都将得到很大的赞赏。

As mentioned on msdn IQueryProvider is focused on creating and executing the query. 正如在msdn上提到的,IQueryProvider专注于创建和执行查询。 Whereas IQueryable is the thing being queried. 鉴于IQueryable是被查询的东西。 Rolling it all together may put similar code together, but it ultimately doesn't respect separation of concerns. 将它们拼凑在一起可能会将类似的代码放在一起,但它最终并不尊重关注点的分离。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM