从表达式树生成SQL [英] Generating SQL from expression trees

查看:435
本文介绍了从表达式树生成SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从表达式树生成oracle sql语句。

或如何从表达式中提取正文的示例

I want to generate oracle sql statements from an expression tree.
or an example how to extract the body from the expression

tableRepository.Select(s =>  s.Id == 1 && s.Description == "ee" )



应生成


should generate

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:

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



循环遍历树?


loop through the tree?

推荐答案

你可以使用LinqPad查看sql。
You can use LinqPad to see the sql.


我不确定你想要实现的目标...如果你想知道如何创建表达式树,请检查:

表达式树(C#)| Microsoft Docs [ ^ ]

如何:使用表达式树构建动态查询(C#) Microsoft Docs [ ^ ]

在运行时动态指定谓词过滤器Microsoft Docs [ ^ ]
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[^]


这篇关于从表达式树生成SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆