FINAL EDIT : I will put the answer here at the top for other people who are searching. The main problem was the namespace mismatch caused by db-first generated EDM attaching '.Models' to the end of the model namespace. This namespace did not matched with the odata namespace so the route was failing. I just edited out all the occurances of '.Models' from the namespace and now it's working.
A newbie trying out Breeze with webApiOdata set up. Sorry if this question is a trivial one.
I have a db generated edmx model with webapi odata controllers. I was having problem with getting the correct metadata to show until I read about the new Breeze EdmBuilder.
That solved the problem of getting the correct metadata to show but now, I can not route to any of the tables. If I try /odata/Customers I get a 406 error.
Before, I was using ODataConventionModelBuilder to set the EntitySets and that worked fine.
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Detail>("Details");
builder.EntitySet<Item>("Items");
builder.EntitySet<Order>("Orders");
builder.EntitySet<Customer>("Customers");
Now, since I am using EdmBuilder, how do I set the EntitySets so that I can route to proper data?
I hope the question makes sense.
* EDIT : I have added the listing of GCSodContext and a snippet from the Customers controller.
namespace GCSbz3.Models
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class GCSodContext : DbContext
{
public GCSodContext()
: base("name=GCSodContext")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Customer> Customers { get; set; }
public virtual DbSet<Detail> Details { get; set; }
public virtual DbSet<Item> Items { get; set; }
public virtual DbSet<Order> Orders { get; set; }
}
}
and Here is the Customers controller
...
using System.Web.Http;
using System.Web.Http.ModelBinding;
using System.Web.Http.OData;
using System.Web.Http.OData.Routing;
using GCSbz3.Models;
namespace GCSbz3.Controllers
{
public class CustomersController : ODataController
{
private GCSodContext db = new GCSodContext();
// GET odata/Customers
[Queryable]
public IQueryable<Customer> GetCustomers()
{
return db.Customers;
}
...
Here is the Customer class.
namespace GCSbz3.Models
{
using System;
using System.Collections.Generic;
public partial class Customer
{
public Customer()
{
this.Orders = new HashSet<Order>();
}
public int CustID { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public string Phone { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
}