创建从一个lambda表达式的字符串
问题描述:
我有采取SQL where子句的功能,我想知道是否有一种方法,使他们所有的强类型。有没有办法采取lambda表达式像=> a.AgencyID == ID,并将其转换为字符串where子句?像AgencyID ='idValue'?
I have functions that take SQL where clauses, and I'm wondering if there's a way to make them all strongly typed. Is there a way to take a lambda expression like a => a.AgencyID == id and convert it to a string where clause? Like "AgencyID = 'idValue'"?
谢谢!
答
你可以把lambda函数到表达式树,然后遍历树来构建您的字符串。
You could turn the lambda function into an expression tree, and then traverse the tree to build your string.