简体   繁体   中英

How to Serialize System.Linq.Expressions?

I am working on WinRT and entity framework (to SQL), the layer that communicates between them is WCF Service.

In the entity framework I am using the Repository Pattern and I have the method:

    public IQueryable<User> GetBySearch(Expression<Func<User, bool>> search)
    {
        return this.Context.Users.Where(search);
    }

Everything works fine, but when I add it to WCF

    [OperationContract]
    IQueryable<User> GetEventBySearch(Expression<Func<User, bool>> search);

and:

    public IQueryable<User> GetEventBySearch(Expression<Func<User, bool>> search)
    {
        IUser user = new UserRepository();
        return user.GetBySearch(search);
    }

But the problem that Expression<TDelegate> is not serializable, therefore, WCF can't serialize it.

So I thought to inherit from it and make it [Serializable] but the problem that it is a sealed class.

This doesn't make sence at all. In fact you try to execute a func in the code of WinRT client on the WCF service. How shoud that work? I think you have to define your own query language that is translated to a expression on the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM