Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple (Dumb) LINQ Provider

Tags:

linq

provider

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.?

like image 896
Ali Kazmi Avatar asked Apr 03 '09 14:04

Ali Kazmi


3 Answers

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!

like image 100
Mia Clarke Avatar answered Nov 14 '22 07:11

Mia Clarke


Give a look to the LINQExtender project, is a toolkit for creating custom LINQ providers.

like image 25
Christian C. Salvadó Avatar answered Nov 14 '22 07:11

Christian C. Salvadó


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.

like image 3
Kevin Driedger Avatar answered Nov 14 '22 08:11

Kevin Driedger