教学实体框架为自定义NodeType生成SQL

时间:2012-07-19 11:06:52

标签: entity-framework expression-trees

是否可以通过使用NodeType Extension和CanReduce = false的自定义Expression继承来自定义SQL的生成?

考虑以下要点,其中Name是ViewModel中的属性,Attribute1是MS SQL中SQL类型列中的属性。

/* may not compile, focus is on SQL generation. */
Expression<Func<ViewModel, bool>> expr = (vm) => vm.Name == "abc" && vm.Attribute1 == 123;
var translator = new CustomExpressionVisitor();
LambdaExpression translated = (LambdaExpression)translator.Visit(expr);

/*
translated has a custom Expression type for vm.Attribute1 == 123 part, it is of type XmlPredicateExpression and this expression has all necessary information to generate an SQL query on this column.
*/

我们如何教导EntityFramework为此表达式生成SQL?有可能吗?

0 个答案:

没有答案