I am trying to add the entity which is related to another entity
onlinedb.DemoShifts.filter("it.EmployeeID ==="+empID).toArray(function (DemoShift) {
DemoShift.forEach(function (demoShift) {
offlinedb.DemoShifts.add(demoShift);
alert("Add DemoShift");
onlinedb.Sites.filter("it.SiteID==="+demoShift.SiteID).toArray(function(Sitess){
Sitess.forEach(function(site){
onlinedb.SiteChains.filter("it.ChainID==="+site.ChainID).toArray(function (chains) {
offlinedb.attach(chains[0]);
alert("Add SiteChain");
});
offlinedb.add(site);
var res = offlinedb.saveChanges();
res.done(function () { alert("Success"); });
res.fail(function (ex) { alert("Success"); });
});
});
});
});
I am getting this error "Context already contains the entity"
What is exactly wrong I am doing Can you tell me is there any way I can check if the entity already exists or something?