We saw that, using WAQS, we can querying directly from the client.
But, when we do this, we sometimes want to be able to filter the result in the server in order to not expose everything to everybody. So it’s important to be able to add some filters in the server on the data sent to the client.
One of the good things with code generation is the ability to use partial methods which often is a very good, flexible and easy way to define configuration IMHO and WAQS uses it a lot.
For example, if you only want to return the orders of the connected customer, you just have to extend NorthwindEntitiesFilters class:
partial class NorthwindEntitiesFilters
partial void ApplyOrdersServerWhere(ref Expression<Func<Order, bool>> filterExpression)
string customerId = GetCurrentCustomerId();
filterExpression = o => o.CustomerId == customerId;
Of course, this filter will be included in LINQ To Entities query anytime we use the Order class in LINQ To WAQS query and therefore will be included in the SQL query.
Note that, for a better understanding of the next posts, we won’t keep this filter.