views:

127

answers:

2

I'm wondering how one would translate a sql string to an expression tree. Currently, in Linq to SQL, the expression tree is translated to a sql statement. How does on go the other way? How would you translate

select * from books where bookname like '%The%' and year > 2008 

into an expression tree in c#?

A: 

http://weblogs.asp.net/rajbk/archive/2007/09/18/dynamic-string-based-queries-in-linq.aspx

update

The Entity framework has the Entity SQL language. Not sure if that is what you want though.

http://msdn.microsoft.com/en-us/library/bb738521.aspx

Raj Kaimal
Well...Sort of. Dynamic Linq allows you to specify your linq lambda expression arguments as strings, but you still have to specify the extension methods (.Select, .Where) of your linq statements directly.
Robert Harvey
it would be nice to not use dynamic linq but purely built from System.Linq.Expressions
Joo Park
A: 

See http://stackoverflow.com/questions/296972/sql-to-linq-tool

Paul Kearney - pk
Well...Sort of. Linqer does reverse-engineer SQL statements into Linq statements, but it does not produce expression trees that you can consume.
Robert Harvey
along the lines of what Robert says....this tool provides the linq statement that is static. It would be nice to great linq statements dynamically at runtime, hense, the expression tree.
Joo Park