i have simple example trying set following schema...
public class foo { public int id { get; set; } public string name { get; set; } public string somethingverybig { get; set; } public list<bar> bars { get; set; } } public class bar { public int id { get; set; } public int fooid { get; set; } public string name { get; set; } }
what trying test using breeze in way disconnected data repository, hand coding fluent api dbcontext. context code below, "foosdb" sdf file deployed project breeze metadata , not real database saving data into.
public class foosdbcontext : dbcontext { public foosdbcontext() : base(nameorconnectionstring: "foosdb") { database.setinitializer<foosdbcontext>(null); } public dbset<foo> foos { get; set; } public dbset<bar> bars { get; set; } public dbset<link> links { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<foo>().haskey(f => f.id); modelbuilder.entity<bar>().haskey(b => b.id); modelbuilder.entity<foo>().hasmany(f => f.bars).withrequired().hasforeignkey(b => b.fooid); } } public class fooscontextprovider : efcontextprovider<foosdbcontext> { public fooscontextprovider() : base() { } protected override list<keymapping> savechangescore(dictionary<type, list<entityinfo>> savemap) { return new list<keymapping>(); } protected override bool beforesaveentity(entityinfo entityinfo) { return true; } protected override dictionary<type, list<entityinfo>> beforesaveentities(dictionary<type, list<entityinfo>> savemap) { // return map of entities want saved. return savemap; } }
everything works great , testing crud operations via project hot towel template, when query foos controller json data looks perfect, when gets transferred breeze/knockout observables data in each "foo.bars" list wrong. taking bar.id = 1 , putting on foo.id = 1, bar.id = 2 , putting on foo.id = 2, , on. though in example bar.id = 2 should on foo.id = 1.
Comments
Post a Comment