WAQS Querying: SQL and polymorphism

7 reasons to use WAQS

WAQS documentation

 

In order to reproduce polymorphism logic in SQL, we can use CASE WHEN syntax.

In LINQ To Entities expression, we can use something like this:

c => c is VIPCustomer ? 0.1 : 0


In this post we saw how to use polymorphism for calculated properties.



As we saw in the previous post, calculating Expression is not basic because of partial method. It’s easier here:



For a VIPCustomer, WAQS uses this basic Expression:



protected internal static new Expression<Func<WebApplication25.VIPCustomer, double>> GetDiscountExpression (
bool isCoalesceEnabled = true)
{
    Expression<Func<WebApplication25.VIPCustomer, double>> exp = (c) => 0.1;
    GetDiscountExpression (ref exp);
    return exp;
}
static partial void GetDiscountExpression (ref Expression<Func<WebApplication25.VIPCustomer, double>> exp);


Now for a Customer, WAQS uses the Condition Expression as expected:



protected internal static Expression<Func<WebApplication25.Customer, double>> GetDiscountExpression (
bool isCoalesceEnabled = true)
{
    Expression<Func<WebApplication25.Customer, double>> exp = (c) => 0;
    var subExpVIPCustomer = VIPCustomerDALSpecifications.GetDiscountExpression ();
    exp = (Expression<Func<WebApplication25.Customer, double>>)exp.Replace(exp.Body,
Expression.Condition(
Expression.TypeIs(exp.Parameters[0], typeof(VIPCustomer)),
subExpVIPCustomer.Body.Replace(subExpVIPCustomer.Parameters[0],
Expression.TypeAs(exp.Parameters[0], typeof(VIPCustomer))),
exp.Body));    
GetDiscountExpression (ref exp);
    return exp; }
This entry was posted in 12253, 16868, 7674. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>