Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:57:25+00:00 2026-06-17T18:57:25+00:00

I have a MVC4 WebAPI controller that returns an IQueryable , and therefore I

  • 0

I have a MVC4 WebAPI controller that returns an IQueryable, and therefore I can use $filter and friends in the URL to manipulate the result from the REST endpoint. Here’s my controller:

public class EnrollmentController : ApiController
{
    [Queryable]
    public IQueryable<tblEnrollment> Get()
    {
        var context = new ProjectEntities();
        context.ContextOptions.LazyLoadingEnabled = false;
        return context.tblEnrollment.AsQueryable();
    }
}

But, like this poster, I’m wanting to make the JSON output format a little different to be friendlier with Ember Data’s expected format. So I’d like to return this instead:

return new { enrollment = context.tblEnrollment.AsQueryable() }; 

However, that breaks OData capability because I’m not returning the IQueryable to the WebAPI layer. So, I’m wondering if there’s a way to do something like this:

return new { enrollment = context.tblEnrollment.AsQueryable().ApplyOData() }; 

Which I’m sure would be way to good to be true…but is there some way to explicitly process the OData parameters against an IQueryable instead of letting the WebAPI layer do it implicitly on the result set returned from a Get method? Or is there another way to accomplish what I want here?

Incidentally, I’m stuck on EF4 for the time being, because I can’t upgrade to VS2012 (and hence to .NET4.5 and hence EF5). I could theoretically upgrade to EF 4.3.1, if it would help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:57:26+00:00Added an answer on June 17, 2026 at 6:57 pm

    Instead of marking your action as [Queryable], you can add a parameter of type ODataQueryOptions and apply it manually. Here’s what it might look like:

    public class EnrollmentController : ApiController
    {
        public object Get(ODataQueryOptions<tblEnrollment> query)
        {
            var context = new ProjectEntities();
            context.ContextOptions.LazyLoadingEnabled = false;
            var queryResults = query.ApplyTo(context.tblEnrollment.AsQueryable());
            return new { enrollment = queryResults };
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MVC4 webapi controller. It has no parameter-less constructors. So, i use
I am starting to use MVC4 Web API project, I have controller with multiple
Using ASP.NET MVC4 I have created a DelegatingHandler in a WebAPI project. I use
In the examples I have seen so far for MVC4 WebApi the following URL
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
I've created a method using the new WebAPI features in MVC4 and have it
I have a layered web application that I built with ASP.NET MVC 4, WebAPI
I have an MVC4 site with a nice customError page that works great if
I have 3 mvc4 sites. Site 1 'www.mydomain.com' is a marketing site that allows
I have a c# mvc4 twitter bootstap appharbor web site. Currently I use Vimeo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.