Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to generate oracle sql statements from an expression tree.
or an example how to extract the body from the expression
C#
tableRepository.Select(s =>  s.Id == 1 && s.Description == "ee" )

should generate
SQL
select * from table where ID= 1 and description = 'ee';


I would like to have an example how to extract every expression in the body of the expression tree

i want to achive something like this:
http://ryanohs.com/2016/04/generating-sql-from-expression-trees/


What I have tried:

C#
Expression<Func<T, bool>> where
expression = where.Body

loop through the tree?
Posted
Updated 8-Mar-18 2:28am
v4
Comments
CHill60 7-Mar-18 3:10am    
And your question is ... what?
The "What I have tried:" section is for the code you are having a problem with
GKP1992 7-Mar-18 3:19am    
Use Where instead of Select.

You can use LinqPad to see the sql.
 
Share this answer
 
Comments
Maciej Los 7-Mar-18 11:26am    
John, i think you misunderstood OP's question. OP knows how to "translate" linq query into sql representation.
Truly i don't know what OP wants to achieve.
Take a look again at the question (formatting has been improved).
#realJSOP 7-Mar-18 11:56am    
I gotta ask - to what end? If he wants to write sql, he should learn how to write sql. Otherwise, just let linq do its job. I honestly can't think of ANY valid use/business case for extracting the sql out of a linq statement IN an application.
I'm not sure what you want to achieve... If you would like to know how to create expression trees, check this:
Expression Trees (C#) | Microsoft Docs[^]
How to: Use Expression Trees to Build Dynamic Queries (C#) | Microsoft Docs[^]
Dynamically specify predicate filters at runtime | Microsoft Docs[^]
 
Share this answer
 
Comments
erik bullens 8-Mar-18 8:27am    
i want to achive something like this:
http://ryanohs.com/2016/04/generating-sql-from-expression-trees/
Maciej Los 8-Mar-18 8:31am    
OK. What stops you?
erik bullens 12-Mar-18 6:58am    
a better example to start from

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900