简单(哑)LINQ 提供程序
编写一个只能使用我的类定义(没有任何对象引用作为属性)并为我提供翻译后的 SQL 的哑 LINQ 提供程序是多么容易啊。 它可以假设属性和列的名称以及类和基础表的名称相同。 你能给我一些指点吗?
How easy would it be to write a dumb LINQ provider that can just use my class definitions (which don't have any object references as properties) and give me the translated SQL. It can assume the name of the properties and the columns to be same as well as the names of the classes and the underlying tables. Can you please give me some pointers.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我花了大约 4 个月的全职工作(每天 8 小时)来构建一个稳定、有效的提供程序,该提供程序实现了 linq 的整个规范。 我想说,大约三周后,我有了一个非常简单、有缺陷且不稳定的版本,所以如果你只是在寻找一些粗糙的东西,我会说你可能会寻找从一周到两个月的任何东西,具体取决于你的水平以及您有哪些类型的要求。
为此,我必须向您推荐 Wayward 博客,Matt 写了一篇关于如何实现 linq 提供程序的非常好的演练,即使您可能无法复制和粘贴,它也会帮助您实现掌握工作时如何思考。 您可以在这里找到 Matt 的演练:http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx 。 我建议您按照 Matt 的方式进行操作,并扩展 Matt 在其教程的第二部分中包含的表达式树访问者。
另外,当我开始使用这个时,我从表达式树可视化器中得到了很多帮助,一旦您可以看到 linq 如何解析为查询,它确实使解析变得更加容易。
建立一个提供者确实很有趣,尽管有时有点令人沮丧。 祝您一切顺利!
It took me about 4 months of fulltime work (8 hours a day) to build a stable, working provider that implements the entire spec of linq. I would say I had a very simple, buggy and unstable version after about three weeks, so if you're just looking for something rough I would say you're probably looking at anything from a week up to two months depending on how good you are and what types of requiements you have.
I must point you to the Wayward blog for this, Matt has written a really good walkthrough on how to implement a linq provider, and even if you're probably not going to be able to copy and paste, it will help you to get to grips with how to think when working. You can find Matt´s walkthrough here: http://blogs.msdn.com/mattwar/archive/2007/07/30/linq-building-an-iqueryable-provider-part-i.aspx . I recommend you go about it the same way Matt does, and extend the expression tree visitor Matt includes in the second part of his tutorial.
Also, when I began working with this, I had so much help from the expression tree visualizer, it really made parsing a whole lot easier once you could see how linq parsed to queries.
Building a provider is really a lot of fun, even if a bit frustrating at times. I wish you all the best of luck!
查看 LINQExtender 项目,它是一个用于创建自定义 LINQ 提供程序的工具包。
Give a look to the LINQExtender project, is a toolkit for creating custom LINQ providers.
另一个给你帮助的选择似乎是 re-linq 这是一个用于创建自定义 LINQ 提供程序的框架。
这是源代码和很好的概述 (pdf) 编写一个内容。
Another option for giving you a leg up seems to be re-linq which is a framework for creating custom LINQ providers.
Here's the Source code and a nice overview (pdf) of what's involved in writing one.
我根据自己从头开始开发 LINQ-to-SQL 提供程序的经验,在我的博客上编写了一系列教程,从表达式树组合阶段(调用 LINQ 方法)开始,继续表达式访问者,分解查询分解为组件,解析 where 子句,生成文本和参数,最后使用 .NET 表达式命名空间将整个内容编译到 IL 中。
我见过许多不完整的帖子,它们承诺解释如何编写提供程序,但远远没有达到目标,几乎没有触及表面,并且实际上没有提供任何远程可执行的东西。
我根据自己的经验编写的博客系列有一个示例项目可供下载,其中包含简单的提供程序,该提供程序仅涵盖教程示例所需的功能。 然而,它还包括支持许多操作(where、join、first、count、top 等)、子查询、嵌套语句等的生产版本。此外,它生成的 SQL 比我的许多操作更干净。我们已经从实体和 LINQ-to-SQL 中看到了这一点。 没有不必要/冗余的嵌套,将所有内容包装在括号中等等。
对于任何具有良好抽象思维水平的人来说,开发这样的提供程序并不是许多人认为的那么困难的任务。 我开发了一个在生产环境中使用了大约 3 个月的兼职工作(意味着一些晚上和周末)的产品。 从一开始,它就以性能和整洁的 SQL 为目标——它已经实现了这一目标。
找到时间来发布这些材料有点困难,但我想 - 如果它可以帮助那里的人,那么没有理由浪费这个经验:
I’ve written a tutorial series on my blog base on my experience developing a LINQ-to-SQL provider from scratch, starting with the expression tree composition stage (calling the LINQ methods), continuing with the expression visitor, breaking down of the query into components, parsing the where clause, generating the text and parameter and, eventually, compiling the whole thing into IL using the .NET expression namespace.
I’ve seen many incomplete posts that promised to explain how to write a provider, falling very short of the mark, barely scratching the surface and not actually delivering anything remotely executable.
The blog series I’ve written based on my experience has a sample project available for download with the simple provider that covers only the functionality required by the tutorial example. However, it also includes the production version supporting a number of operations (where, join, first, count, top, etc.), subqueries, nested statements, and etc. Additionally, it produces a cleaner SQL than a lot of what I’ve seen from Entities and LINQ-to-SQL. There’s no unnecessary/redundant nesting, wrapping everything in brackets and etc.
For anyone with a good level of abstract thinking, developing such a provider isn’t such a difficult task many set it out to be. I’ve developed one that’s used in production environment in about 3 months of part time work (meaning some evenings and weekends). From the get go it was aimed with performance and tidy SQL in mind – a goal it achieved.
It was a little hard to find the time to publish this material, but I thought – if it may help someone out there, there’s no reason for this experience to go to waste:
我创建了一个项目“LinqToAnything”,旨在使其非常非常容易地实现(简单) Linq 提供商。
I have created a project 'LinqToAnything' which is designed to make it very very easy to implement a (simple) Linq provider.