I have a 4 layered architecture project, i.e. UserInterface, BusinessLogic, Service (WCF) and DataAccess (EF6) layers. I have exposed methods on my service that accept an expression which I can pass to my data access layer to be evaluated using EF. However, this does not work because the Expression<Func>
is not serializable.
On my client end I want to be able to build queryable expressions to send to the server side and return the correct projection.
Server Side:
public virtual IEnumerable<Person> Get(Expression<Func<Person, bool>> expression)
{
using (var ctx = MyContext())
{
IQueryable<PersonDto> col = ctx.DbContext.People.Where(expression);
//
return col.ToList();
}
}
Client side:
public IEnumerable<PersonDto> GetFromService(Expression<Func<PersonDto, bool>> expression)
{
using (MyService client = new MyService())
{
return client.Get(expression);
}
}
Is there an alternative to the way I'm doing this? And is there a reason why expressions and funcs are not serializable?