我在我的第一次嘗試拉滿實體圖形與微風和EF6(Hottowel /約翰·帕帕味)微風擴展性能 - 如何在控制器陣列
我有一個實體失蹤的理解的關鍵部分引用的政策-P_Locations-P_Hazards父子,祖孫關係
我希望看到所有策略的圖形爲一個客戶
總之我查詢返回形在我所期望的JSON(在XHR證實查看器)和data.results允許我深入(通過bac kingstore - man我們需要像C#這樣的JavaScript瀏覽器)來查看兒童和孫子的數組。我看到所有的政策,地點和危害我希望爲客戶端(DLL版本和型號/ modelmap代碼在帖子的末尾)
的DataContext:
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;
}
);
}
如果我深入研究datacontext中的策略或控制器中的vm.Policies中的策略,我會看到駱駝封裝的數組。
但
vm.Policies.p_Locations是不確定的。當然,我也想引用vm.Policies.p_Locations.p_Hazards。
我爲了參考綁定數據圖而丟失了什麼?
BreezeController:
[HttpGet]
public IQueryable<Policy> Policies()
{
return _repository.Policies;
}
PwiRepository
public IQueryable<Policy> Policies
{
get { return Context.Policies; }
}
而創建此要求:
Request URL:http://localhost:29130/breeze/Breeze/Policies?$expand=P_Locations%2CP_Locations%2FP_Hazards&clients_id=439
使用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 件
<packages>
<package id="Breeze.Server.ContextProvider" version="1.4.17" targetFramework="net45" />
<package id="Breeze.Server.ContextProvider.EF6" version="1.4.17" targetFramework="net45" />
<package id="Breeze.Server.WebApi2" version="1.4.17" targetFramework="net45" />
<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.OData" version="5.2.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.0" targetFramework="net45" />
<package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net45" />
<package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.4.0" targetFramework="net45" />
<package id="System.Spatial" version="5.6.2" targetFramework="net45" />
<package id="WebActivator" version="1.5.3" targetFramework="net45" />
</packages>
我有策略 - 的父子,祖孫關係P_Locations-P_Hazards 以下是模型和模型映射的相關部分
P_Location型號:
public partial class P_Location
{
public P_Location()
{
this.P_GlCoverages = new List<P_GlCoverage>();
this.P_Hazards = new List<P_Hazard>();
this.P_PropertyCoverages = new List<P_PropertyCoverage>();
}
public int P_Locations_id { get; set; }
public int Policies_id { get; set; }
......
public virtual Policy Policy { get; set; }
public virtual ICollection<P_Hazard> P_Hazards { get; set; }
P_LocationMap
// Relationships
this.HasRequired(t => t.Policy)
.WithMany(t => t.P_Locations)
.HasForeignKey(d => d.Policies_id);
P_Hazard型號
public Policy Policy { get; set; }
public P_Location P_Location { get; set; }
P_HazardMap
// Relationships
this.HasRequired(t => t.P_Location)
.WithMany(t => t.P_Hazards)
.HasForeignKey(d => d.P_Locations_id);
進入孫子的每個實體似乎都有一個entityAspect屬性。如果我鑽到p_Locations entityAspect.entityManager我看到metadataStore:我 _ctorRegistry:對象 _deferredTypes:對象 _entityTypeResourceMap:對象 ... P_Hazard:#Pwi.Model.Models: 「P_Hazards」 P_Location:#Pwi.Model。模型:「P_Locations」 ... 策略:#Pwi.Model.Models:「策略」 __proto__:這是我期望的模型對象。在原始問題中發佈上面的服務器端代碼。 – 2014-09-01 18:38:42
我不確定我是否真的在意,但誰能告訴我誰投票否決了這個問題,爲什麼?我認爲它徹底解釋了這個問題,並直接針對傑伊的請求發佈了更多信息。 – 2014-09-01 19:32:52
好的,重新閱讀你的文章,當你說「看到所有的政策,地點和危害」,但「Policies.p_Locations未定義」時,我不確定我是否理解。你怎麼能有兩個?你在哪裏「看到」政策,地點和危害?此外,您應該訪問「then」承諾中的「data.results」屬性,而不僅僅是「數據」。 – 2014-09-01 19:57:17