1

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?

Nitzanu
  • 84
  • 8
  • you can check this [answer](https://stackoverflow.com/questions/26038856/how-to-return-a-file-filecontentresult-in-asp-net-webapi) for returning your data as file. – Vijay Nov 03 '20 at 05:35
  • The problem is returning the data as file with the Odata filter, just returning a file works perfectly – Nitzanu Nov 04 '20 at 06:59

1 Answers1

1

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.

vatro
  • 11
  • 2