Uncaught Error: There is no metadata available for this query
Uncaught Error: There is no metadata available for this query
*我正在 VS2012 中使用 HotTowel SPA 开发一个演示应用程序。使用 breeze 我试图公开模型并将其用于查询数据库。我使用此 link http://www.codeproject.com/Articles/730450/Creating-Single-Page-Application-using-Hot-Towel-T
作为此应用程序的参考
这是我的一些代码。
//我的Class
public class JobDemoClass
{
public int Id { get; set; }
public string JobName { get; set; }
public string JobDescription { get; set; }
public DateTime StartTime { get; set; }
}
// 我的 DbContext
public class JobDemoDbContext : DbContext
{
public DbSet<JobDemoClass> JobDemo { get; set; }
public JobDemoDbContext()
: base("SPAConnection")
{
Database.SetInitializer<JobDemoDbContext>(null);
}
}
//我的控制器
[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;
}
//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}];
但是我在使用
时遇到了问题
manager.ExecuteQueryLocally.from("database");
//数据库是控制器中定义的方法
//错误
未捕获的错误:没有可用于此查询的元数据
当我尝试导航到 "jobadd" 和 "jobedit" 视图时出现此错误。
我尝试更改一些代码,但仍然显示相同的错误
当您 ExecuteQueryLocally
时,breeze 需要知道它应该查询什么类型的实体。它通过将 .from
子句中指定的字符串与实体元数据进行匹配来实现。在元数据中,每个实体都有一个 defaultResourceName
属性 指示用于查询这些实体的服务器资源名称的预期名称(Web API 控制器上的方法名称)。
通常 defaultResourceName
是实体名称的复数形式,因此您的 JobDemo
实体可能具有 JobDemos
的默认资源名称。尝试使用
var query = breeze.EntityQuery.from('JobDemos');
var jobDemos = manager.executeQueryLocally(query);
或者:
var query = breeze.EntityQuery.from('database').toType('JobDemo');
var jobDemos = manager.executeQueryLocally(query);
有关详细信息,请参阅 Breeze documentation on Querying Locally。
*我正在 VS2012 中使用 HotTowel SPA 开发一个演示应用程序。使用 breeze 我试图公开模型并将其用于查询数据库。我使用此 link http://www.codeproject.com/Articles/730450/Creating-Single-Page-Application-using-Hot-Towel-T
作为此应用程序的参考这是我的一些代码。
//我的Class
public class JobDemoClass
{
public int Id { get; set; }
public string JobName { get; set; }
public string JobDescription { get; set; }
public DateTime StartTime { get; set; }
}
// 我的 DbContext
public class JobDemoDbContext : DbContext
{
public DbSet<JobDemoClass> JobDemo { get; set; }
public JobDemoDbContext()
: base("SPAConnection")
{
Database.SetInitializer<JobDemoDbContext>(null);
}
}
//我的控制器
[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;
}
//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}];
但是我在使用
时遇到了问题manager.ExecuteQueryLocally.from("database");
//数据库是控制器中定义的方法
//错误 未捕获的错误:没有可用于此查询的元数据
当我尝试导航到 "jobadd" 和 "jobedit" 视图时出现此错误。
我尝试更改一些代码,但仍然显示相同的错误
当您 ExecuteQueryLocally
时,breeze 需要知道它应该查询什么类型的实体。它通过将 .from
子句中指定的字符串与实体元数据进行匹配来实现。在元数据中,每个实体都有一个 defaultResourceName
属性 指示用于查询这些实体的服务器资源名称的预期名称(Web API 控制器上的方法名称)。
通常 defaultResourceName
是实体名称的复数形式,因此您的 JobDemo
实体可能具有 JobDemos
的默认资源名称。尝试使用
var query = breeze.EntityQuery.from('JobDemos');
var jobDemos = manager.executeQueryLocally(query);
或者:
var query = breeze.EntityQuery.from('database').toType('JobDemo');
var jobDemos = manager.executeQueryLocally(query);
有关详细信息,请参阅 Breeze documentation on Querying Locally。