You perhaps saw in the previous post, WAQS adds a partial method to change the generated expression. In the future, when L2E to L2O switching will work, you could define it to return null if the expression is not usable in L2E.
In addition, sometimes, because of SQL aspects, you could want to use a different expression for L2E calculation (without any null test for example).
So you can use this partial method.
Now we will add this new specification method:
public static string GetCustomerName(this Order o)
The GetCustomerName method on Order depends on the GetCustomerName on Customer. So if we want to redefine the Customer GetCustomerName expression using partial method, we have to use this new expression to calculate Order CustomerName.
So, how does it work?
WAQS uses a fake expression that it replaces then by the Customer GetCustomerNameExpression one:
protected internal static Expression<Func<WebApplication25.Order, string>> GetCustomerNameExpression
(bool isCoalesceEnabled = true)
Func<WebApplication25.Customer, string> getCustomerName_Customer = (_) => default(string);
Expression<Func<WebApplication25.Order, string>> exp = (o) => getCustomerName_Customer(o.Customer);
Func<Expression, Expression> replaceExpFunc = null;
replaceExpFunc = e =>
var invocationExpression = e as InvocationExpression;
if (invocationExpression == null ||
(memberExpression = invocationExpression.Expression as MemberExpression) == null)
var getCustomerName_CustomerSubExp =
CustomerDALSpecifications.GetCustomerNameExpression (isCoalesceEnabled : false);
if (getCustomerName_CustomerSubExp == null)
Expression subExp = getCustomerName_CustomerSubExp.Body
exp = (Expression<Func<WebApplication25.Order, string>>)exp.Replace(replaceExpFunc);
GetCustomerNameExpression (ref exp);
In order to avoid a complex analyze in WAQS to build the ExpressionTree at code generation, this way is easier with an insignificant cost at runtime.
However, in the future, WAQS we could think about this optimization.