*I am developing a demo application using HotTowel SPA in VS2012. Using breeze I am trying to expose the model and use it for querying the database. I used reference for this application using this link http://www.codeproject.com/Articles/730450/Creating-Single-Page-Application-using-Hot-Towel-T
Here is some of my code.
// My Class
public class JobDemoClass
{
public int Id { get; set; }
public string JobName { get; set; }
public string JobDescription { get; set; }
public DateTime StartTime { get; set; }
}
// My DbContext
public class JobDemoDbContext : DbContext
{
public DbSet<JobDemoClass> JobDemo { get; set; }
public JobDemoDbContext()
: base("SPAConnection")
{
Database.SetInitializer<JobDemoDbContext>(null);
}
}
//My Controller
[BreezeController]
public class ScottController : ApiController
{
readonly EFContextProvider<JobDemoDbContext > _contextProvider = new EFContextProvider<JobDemoDbContext >();
[System.Web.Http.HttpGet]
public string Metadata()
{
return _contextProvider.Metadata();
}
[System.Web.Http.HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
return _contextProvider.SaveChanges(saveBundle);
}
[System.Web.Http.HttpGet]
public IQueryable database()
{
return _contextProvider.Context.JobDemo;
}
//Some Route in Shell.js
var routes = [
{ route: '', moduleId: 'jobs', title: 'Scheduled Jobs', nav: 1 },
{ route: 'jobadd', moduleId: 'jobadd', title: 'Add a job', nav: 2 },
{route:'JobEdit/:id',moduleId: 'jobedit', name : 'Edit Job', visible: false}];
But here I m facing a problem , while using
manager.ExecuteQueryLocally.from("database");
// database is a method defined in the controller
//Error Uncaught Error: There is no metadata available for this query
This error is coming when I am trying to navigate the to "jobadd" and "jobedit" view.
I tried changing some of my code but still its showing the same error
When you ExecuteQueryLocally
, breeze needs to know what type of entities it is supposed to query. It does this by matching the string specified in the .from
clause against the entity metadata. In the metadata, each entity has a defaultResourceName
property indicating the expected name of the server resource name (method name on your Web API controller) that is used for querying those entities.
Usually the defaultResourceName
is the plural of the entity name, so your JobDemo
entity probably has a defaultResourceName of JobDemos
. Try using
var query = breeze.EntityQuery.from('JobDemos');
var jobDemos = manager.executeQueryLocally(query);
Or:
var query = breeze.EntityQuery.from('database').toType('JobDemo');
var jobDemos = manager.executeQueryLocally(query);
See the Breeze documentation on Querying Locally for more info.