0
我想訪問在客戶端新近創建的服務器端的導航屬性。Breezejs BeforeSaveEntitiesDelegate:無法訪問導航屬性
數據模型。
public class Foo
{
public string ID { get; set; } //Primary key
public string Status { get; set; }
public virtual ICollection<Bar> Bars { get; set; }
}
public class Bar
{
public string ID { get; set; } //Foreign Key
public string Notes { get; set; }
}
在客戶端: 我已經有父對象(ID 123)和我創建一個新的子對象
function changeParentAndChild(foo){
foo.Status = 'Closed';
var barnotes = em.createEntity('Bar', { ID: 123});
barnotes.Notes = 'Sample text';
foo.Bars.push(barnotes);
}
節省使用manager.saveChanges();
在服務器端
BeforeSaveEntitiesDelegate += PerformPreSaveValidation()
public Dictionary<Type, List<EntityInfo>> PerformPreSaveValidation(Dictionary<Type, List<EntityInfo>> saveMap)
{
foreach (Type entityType in saveMap.Keys)
{
if (entityType.Name == "Foo")
{
foreach (EntityInfo ei in saveMap[entityType])
{
Foo objFoo = ((Foo)ei.Entity);
switch (objFoo.Status)
{
case "Closed":
//access parent id and status
string id = objFoo.ID;
string status = objFoo.Status
//access navigation property
string barnotes = objFoo.Bars.Last().Notes;
//invoke external method
Externalmethod(is,status,Notes)
break;
default:
break;
}
}
}
}
return saveMap;
}
當我通過savemap循環並嘗試訪問導航屬性。我看到它是空的。但saveMap是一種有兩個項目,一個父Foo和一個爲孩子酒吧
應用程序使用:
Breezejs: Version: "1.4.7", metadataVersion: "1.0.5"
EF6
ASP.net
web api
Angular
感謝, 拉吉夫。