Can I extend the operators supported by LINQ to SQL?

If I wanted strongly enough, can I add additional LINQ constructs to LINQ-to-SQL (as I could when creating my own LINQ provider)? For example, many of the built-in LINQ ( XYZ.Any()

) operators convert directly to SQL (for example IF EXISTS(XYZ)

).

If I needed a custom construct, would I even be able to scale up the set, or does this need to be baked into the actual LINQ to SQL provider?

How do I add a new operator implementation? Are C # extension methods sufficient to get the job done?

If the answer is yes, could someone so inclined to replace many (all?) Of the sproc capabilities through dynamic SQL generated by LINQ-to-SQL?

+2


source to share


2 answers


In theory, you could add support for arbitrary expressions to the LINQ provider, but Pavel is correct that LINQ to SQL won't work as a starting point. I would look at SubSonic or NHibernate, which have LINQ providers as well. When the provider supports an expression, you just need to create an equivalent extension method on IQueryable<T>

- reflect System.Linq.Queryable

for details.



That said, parsing expression trees is definitely not for the faint of heart. If you're not really interested in AST theory, it would probably be easier to just extend the OSS ORM in a "normal" way.

+1


source


No, LINQ to SQL is not extensible. The best you can do is use stored procedures.



+1


source







All Articles