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();