Web API Queryable - how to apply AutoMapper?

前端 未结 4 1159
一整个雨季
一整个雨季 2020-11-30 23:03

I\'ve got a simple WebApi method like this decorated with the OData queryable attribute.

    [Queryable]
    public virtual IQueryable Get()         


        
4条回答
  •  感情败类
    2020-11-30 23:53

    There is a better solution. Try this:

    public virtual IQueryable Get(ODataQueryOptions query)
    {
        var people = query.ApplyTo(uow.Person().GetAll());
        return ConvertToDtos(people);
    }
    

    This will make sure the query runs on Person instead of PersonDTO. If you want the conversion to happen through an attribute instead of in code, you'll still want to implement an action filter similar to what you put up.

提交回复
热议问题