Search code examples
entity-frameworklambdawcf-data-servicesinterceptor

How to hide some columns with EF + lambda expression (for WCF QueryInterceptor)


I have a Web App with a WCF OData Service. I have a model called Guest with some properties: Id, FullName, Username, Email...

The WCF data service works like a feed, so I want to hide the Email columns, but I do not know how.

public Expression<Func<Guest, bool>> OnQueryGuests()
{
    if (!IsAuthenticated())
        return c => c________;//what should return here???
}

My temporary solution is to disable the service for all users not logged on.


Solution

  • With entity framework you will need to project the results into a subclass then tell WCF Data Services that the subclass is the entity. By intercepting the IQueryable this is all possible. It's a little bit of work but with the help of Derrick VanArnam MS Example I was able to create an expression interceptor that would modify the expression tree to remove the bindings of properties that aren't needed.