I am currently running a web API with oData filter requests as follows:
public IQueryable<OrganizationViewModel> Get(ODataQueryOptions<Organization> oDataQuery) { var query = new FindOrganizationsQuery(oDataQuery); var result =_findOrganizationsQueryHandler.Execute(query); return result.Organizations.Select(o => new OrganizationViewModel { Id = o.PublicId, Name = o.Name }); }
The handler looks like this:
public FindOrganizationsQueryResult Execute(FindOrganizationsQuery request) { var organizations = request.ODataQuery.ApplyTo(_mgpQueryContext.Organizations).Cast<Organization>(); return new FindOrganizationsQueryResult(organizations); }
And the request class looks like this:
public class FindOrganizationsQuery { public FindOrganizationsQuery(ODataQueryOptions<Organization> oDataQuery) { ODataQuery = oDataQuery; } public ODataQueryOptions<Organization> ODataQuery { get; set; } }
So, if I pass the oData filter with the request, it handles nicely, and it all works great.
But now instead of passing the ODataQueryOptions type to the Get operation, I would like to have a FindOrganizationsQuery class, for example:
public IQueryable<OrganizationViewModel> FindOrganizations(FindOrganizationsQuery query) {
However, query parameters are always zero. How to pass oData filter if ODataQueryOptions parameters are in another class?
source share