Javascript Breeze扩展属性-如何在控制器阵列中引用
在我第一次尝试为一个具有Breeze和EF6(Hottower/John Papa flavor)的实体绘制完整的实体图时,我缺少了一个关键的理解 我的亲子孙关系为政策-p_位置-p_危险 我想查看一个客户端的所有策略的图表 简言之,我的查询返回我期望的JSON格式(在XHR查看器中确认)和data.results,允许我深入查看(通过backingstore-man,我们是否需要像C#这样的javascript查看器)以查看子孙孙的数组。我看到了我期望的客户机的所有策略、位置和危害(文章末尾的dll版本和模型/模型映射代码) datacontext:Javascript Breeze扩展属性-如何在控制器阵列中引用,javascript,angularjs,breeze,hottowel,Javascript,Angularjs,Breeze,Hottowel,在我第一次尝试为一个具有Breeze和EF6(Hottower/John Papa flavor)的实体绘制完整的实体图时,我缺少了一个关键的理解 我的亲子孙关系为政策-p_位置-p_危险 我想查看一个客户端的所有策略的图表 简言之,我的查询返回我期望的JSON格式(在XHR查看器中确认)和data.results,允许我深入查看(通过backingstore-man,我们是否需要像C#这样的javascript查看器)以查看子孙孙的数组。我看到了我期望的客户机的所有策略、位置和危害(文章末尾的
function getPoliciesByClientsId(clientsid) {
var policies;
return EntityQuery.from('Policies')
.withParameters({ clientsid: clientsid })
.expand('P_Locations, P_Locations.P_Hazards')
.using(manager).execute()
.then(querySucceeded, _queryFailed);
function querySucceeded(data) {
policies = data.results;
log('Retrieved [Policy] from remote data source', policies.length, true);
return policies;
}
}
function getPoliciesByClientsId(clientsid) {
return datacontext.getPoliciesByClientsId(clientsid).then(function(data) {
vm.Policies = [];
vm.Policies = data;
// at this point vm.Policies shows an object array
// and I can see p_Locations for each policy and p_Hazards for each location
// but vm.Policies.p_locations is undefined
return vm.Policies;
}
);
}
[HttpGet]
public IQueryable<Policy> Policies()
{
return _repository.Policies;
}
控制器:
function getPoliciesByClientsId(clientsid) {
var policies;
return EntityQuery.from('Policies')
.withParameters({ clientsid: clientsid })
.expand('P_Locations, P_Locations.P_Hazards')
.using(manager).execute()
.then(querySucceeded, _queryFailed);
function querySucceeded(data) {
policies = data.results;
log('Retrieved [Policy] from remote data source', policies.length, true);
return policies;
}
}
function getPoliciesByClientsId(clientsid) {
return datacontext.getPoliciesByClientsId(clientsid).then(function(data) {
vm.Policies = [];
vm.Policies = data;
// at this point vm.Policies shows an object array
// and I can see p_Locations for each policy and p_Hazards for each location
// but vm.Policies.p_locations is undefined
return vm.Policies;
}
);
}
[HttpGet]
public IQueryable<Policy> Policies()
{
return _repository.Policies;
}
如果我深入研究datacontext中的策略或controller中的vm.Policys,我会看到驼峰式数组
但是
vm.Policies.p_位置未定义。当然,我也想参考vm.Policies.p_位置.p_危险
为了引用绑定数据图,我遗漏了什么
BreezeController:
function getPoliciesByClientsId(clientsid) {
var policies;
return EntityQuery.from('Policies')
.withParameters({ clientsid: clientsid })
.expand('P_Locations, P_Locations.P_Hazards')
.using(manager).execute()
.then(querySucceeded, _queryFailed);
function querySucceeded(data) {
policies = data.results;
log('Retrieved [Policy] from remote data source', policies.length, true);
return policies;
}
}
function getPoliciesByClientsId(clientsid) {
return datacontext.getPoliciesByClientsId(clientsid).then(function(data) {
vm.Policies = [];
vm.Policies = data;
// at this point vm.Policies shows an object array
// and I can see p_Locations for each policy and p_Hazards for each location
// but vm.Policies.p_locations is undefined
return vm.Policies;
}
);
}
[HttpGet]
public IQueryable<Policy> Policies()
{
return _repository.Policies;
}
使用manager.metadataStore.getEntityType('p_Location')然后钻取到导航属性我找到了这些属性
navigationProperties: Array[4]0:
dassociationName: "P_Hazard_P_Location"
entityType: l
entityTypeName: "P_Hazard:#Pwi.Model.Models"
foreignKeyNames: Array[0]
foreignKeyNamesOnServer: Array[0]
invForeignKeyNames: Array[1]
invForeignKeyNamesOnServer: Array[1]
inverse: disScalar: falsename: "p_Hazards"
nameOnServer: "P_Hazards"
parentType: lvalidators: Array[0]
associationName: "P_Location_Policy"
entityType: lentityTypeName: "Policy:#Pwi.Model.Models"
foreignKeyNames: Array[1]
foreignKeyNamesOnServer: Array[1]
invForeignKeyNames: Array[0]
invForeignKeyNamesOnServer: Array[0]
inverse: disScalar: truename: "policy"
nameOnServer: "Policy"parentType: l
relatedDataProperties: Array[1]validators: Array[0]__proto__: Objectlength: 4
这是dll
碎片
p_危险模型
public Policy Policy { get; set; }
public P_Location P_Location { get; set; }
p_危险图
// Relationships
this.HasRequired(t => t.P_Location)
.WithMany(t => t.P_Hazards)
.HasForeignKey(d => d.P_Locations_id);
首先,我要检查以确保查询返回的对象实际上是实体。i、 e.它们是否都有“实体方面”属性?如果不是,则返回的是投影而不是实体。发生这种情况的原因多种多样,但通常是由于namingConvention问题或EntityQuery上缺少“toType”调用。(如果查询端点不在实体类型/资源名称映射中(参数化查询中经常出现这种情况),则需要此选项) 我还将使用getEntityType查看元数据存储,并确保每个实体的属性名称都是您所期望的
您还可以发布服务器端查询吗 孙辈中的每个实体似乎都有一个entityAspect属性。如果深入p_Locations entityAspect.entityManager,我会看到元数据存储:I_ctorRegistry:Object\u deferredTypes:Object\u entityTypeResourceMap:Object。。。P#u危险:#Pwi.Model.Models:“P#u危险”P#u位置:#Pwi.Model.Models:“P#u位置”。。。Policy:#Pwi.Model.Models:“Policies”proto:Object,这是我期望的模型。在原始问题中发布上面的服务器端代码。我不确定我是否真的在乎,但有人能告诉我谁否决了这个问题,为什么?我认为它彻底地解释了这个问题,并直接解决了Jay的要求,我发布了进一步的信息。好吧,重新阅读你的帖子,我不确定我是否理解你说的“查看所有政策、位置和危险”,但“policies.p_位置未定义”。你怎么能两者兼得?您在哪里“看到”政策、位置和危险?另外,您应该访问“then”承诺中的“data.results”属性,而不仅仅是“data”。不确定是谁给您打分,但我刚刚重新打分。谢谢Jay。我的意思是,在JSON中,我看到了所有预期的数据和data.results中的数据。在datacontext中,我可以钻取策略并查看p_位置的数组,然后钻取每个p_位置以查看p_危险的数组。在每种情况下,我都通过钻取到_backingstore来看到这些。钻取在控制器中接收数据的vm.Policys时也是如此。我的期望是vm.Policies.p_位置将是一个可绑定的数组。我是否需要在某处显式声明vm.Policies.p_Locations=[]呢?