title: OData Error: The query specified in the URI is not valid. The property cannot be used in the query option
body: <p>I'm trying to get an OData endpoint up and working and I'm having this error that even Google doesn't have much to say about.</p>
  
  <p>I have created an Entity Framework EDMX context (database first), had the designer generate 2 models from it.</p>
  
  <p>Everything is working fine, except <code>$filter</code> queries fail.</p>
  
  <p>I can do this fine:</p>
  
  <pre><code>http://localhost:27164/Projects(6587660)
  </code></pre>
  
  <p>Which retrieves the Project with a primary ID of 6587660.</p>
  
  <p>But any <code>$filter</code> requests as such:</p>
  
  <pre><code>http://localhost:27164/Projects?$filter=ProjectID eq 6587660
  </code></pre>
  
  <p>Will fail with the following error:</p>
  
  <blockquote>
    <p>The query specified in the URI is not valid. The property 'ProjectID' cannot be used in the $filter query option.</p>
  </blockquote>
  
  <p>I've also tried querying other properties, string properties too. Same error.</p>
  
  <p>I've checked that the model generated by EF doesn't have any attributes on the properties, they don't.</p>
  
  <p>Here's my Register method in WebApiConfig.cs module:</p>
  
  <pre><code>using System.Web.OData.Builder;
  using System.Web.OData.Extensions;
  
  public static void Register(HttpConfiguration config)
  {
      // Web API configuration and services
      // Configure Web API to use only bearer token authentication.
      config.SuppressDefaultHostAuthentication();
      config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
  
  
      ODataModelBuilder builder = new ODataConventionModelBuilder();
      builder.EntitySet&lt;DB.Project&gt;("Projects");
      config.MapODataServiceRoute(
          routeName: "ODataRoute",
          routePrefix: null,
          model: builder.GetEdmModel()
      );           
  
  }
  </code></pre>
  
  <p>Here's the Projects controller (GetProjects is the called method when doing a $filter query):</p>
  
  <pre><code>public class ProjectsController : ODataController
  {
      private AppContext db = new AppContext();
  
      //I've tried decorating with that: [EnableQuery(AllowedQueryOptions = System.Web.OData.Query.AllowedQueryOptions.All, AllowedArithmeticOperators = System.Web.OData.Query.AllowedArithmeticOperators.All)] and no go
      [EnableQuery]
      public IQueryable&lt;Project&gt; GetProjects()
      {
          return db.Projects;
      }
  
      // GET: odata/Projects(5)
      [EnableQuery]
      public SingleResult&lt;Project&gt; GetProject([FromODataUri] int key)
      {
          return SingleResult.Create(db.Projects.Where(project =&gt; project.ProjectID == key));
      }
  
      /*
      // PUT: odata/Projects(5)
      public IHttpActionResult Put([FromODataUri] int key, Delta&lt;Project&gt; patch)
      {
          Validate(patch.GetEntity());
  
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          Project project = db.Projects.Find(key);
          if (project == null)
          {
              return NotFound();
          }
  
          patch.Put(project);
  
          try
          {
              db.SaveChanges();
          }
          catch (DbUpdateConcurrencyException)
          {
              if (!ProjectExists(key))
              {
                  return NotFound();
              }
              else
              {
                  throw;
              }
          }
  
          return Updated(project);
      }
  
      // POST: odata/Projects
      public IHttpActionResult Post(Project project)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          db.Projects.Add(project);
          db.SaveChanges();
  
          return Created(project);
      }
  
      // PATCH: odata/Projects(5)
      [AcceptVerbs("PATCH", "MERGE")]
      public IHttpActionResult Patch([FromODataUri] int key, Delta&lt;Project&gt; patch)
      {
          Validate(patch.GetEntity());
  
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          Project project = db.Projects.Find(key);
          if (project == null)
          {
              return NotFound();
          }
  
          patch.Patch(project);
  
          try
          {
              db.SaveChanges();
          }
          catch (DbUpdateConcurrencyException)
          {
              if (!ProjectExists(key))
              {
                  return NotFound();
              }
              else
              {
                  throw;
              }
          }
  
          return Updated(project);
      }
  
      // DELETE: odata/Projects(5)
      public IHttpActionResult Delete([FromODataUri] int key)
      {
          Project project = db.Projects.Find(key);
          if (project == null)
          {
              return NotFound();
          }
  
          db.Projects.Remove(project);
          db.SaveChanges();
  
          return StatusCode(HttpStatusCode.NoContent);
      }
      */
  
      protected override void Dispose(bool disposing)
      {
          if (disposing)
          {
              db.Dispose();
          }
          base.Dispose(disposing);
      }
  
      private bool ProjectExists(int key)
      {
          return db.Projects.Count(e =&gt; e.ProjectID == key) &gt; 0;
      }
  }
  </code></pre>
  
  <p>This is the first time I'm using OData with Database First so I'm not sure what's causing this.</p>
  
  <p>I'm using the latest runtimes from Nuget on .NET 4.5.2.</p>