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?

2
  • you can check this answer for returning your data as file. Commented Nov 3, 2020 at 5:35
  • The problem is returning the data as file with the Odata filter, just returning a file works perfectly Commented Nov 4, 2020 at 6:59

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.