WAQS: Server calculated properties

7 reasons to use WAQS

WAQS documentation


Sometimes, we want to calculate the property on the server only.

For this, WAQS has an attribute to specify it: NotApplicableOnClient.

Sometimes, we need to execute a query into the DB to get the value of the calculated property.

For this, you can just use the DAL Context Interface as a parameter of the method. If the method if an extension method on an entity and only has the entity and the context as parameter, it will be transformed into a property by WAQS.

public static int GetOrdersCount(this Customer c, INorthwindWAQSEntities context)
    return context.Orders.Where(o => o.CustomerId == c.Id).Count();

If you use the context, the attribute NotApplicableOnClient is useless. The calculation will only be on the server anyway.

In this case, we would be able to use the property on the server. On the client, we will only have this code that I will explain in a future post:

public int OrdersCount
        return Specifications != null && Specifications.HasOrdersCount ? Specifications.OrdersCount : default (int);
        throw new System.InvalidOperationException();
This entry was posted in 16868. Bookmark the permalink.

2 Responses to WAQS: Server calculated properties

  1. FremyCompany says:

    Wouldn’t it possible to use an async function like GetOrdersCount() that we could use client side and that would queue a query where the server computes the value, returns it back, and then the client finally adds it to the specifications?

    Last time I worked on a data-driven project, I had a few cases where I had to bind to informations in dialogs I didn’t think I would need before, it would be annoying to have to track the dependencies manually 😉

  2. Matthieu MEZIL says:

    Yes you can. It will be the subject of a future post 🙂

Leave a Reply

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