Nitzanu
Nitzanu

Reputation: 84

C# OData use query parameter as input but return a custom response

I'm trying to add a new method to my OData controller, this method's purpose is to generate a user report file based on a given filter. that filter will be applied to all the users in the system and the report will be generated on the remaining users after filtering. that report is a PDF file, therefore I'm returning it as a byte[] and the client will have to write it to the disk. this is my code:

    [HttpGet]
    public IHttpActionResult GenerateUsersReport(ODataQueryOptions options)
    {
        var users = (IQueryable<Incident>)options.ApplyTo(_LINQ.UserQuery);
        var usersIDs = users.Select(user => user.ID);
        byte[] report = // Generate query according to the user IDs
        return new FileResponse(report, "application/pdf");
    }

but when doing that, I get an error saying

500 Cannot create an EDM model as the action 'GenerateUsersReport' on controller 'Users' has a return type 'System.Web.Http.IHttpActionResult' that does not implement IEnumerable.

from that error, I understand that OData will expect an IEnumerable to apply the query again afterward. how can I eliminate that issue and use the query only in my code as shown and not have it filtered after the return?

Upvotes: 1

Views: 558

Answers (1)

vatro
vatro

Reputation: 11

I know this is old, but it still pops out in searches. So, now this will work (it might not be working at the time of question):

public IHttpActionResult GenerateUsersReport(ODataQueryOptions<User> options)

if my assumption that this is to be performed on entity called User.

Upvotes: 1

Related Questions