|
Hi,
you asked:
However, I'm not sure how to implement the step that says
"After save, the application might export the saved rep back into the main EM where it now displays in the grid in its post-save glory."
Basically you will import the graph back to the main EM.
It seems when I call SaveChangesAsync on the second entity model it is not being committed to the database.
Are you checking the datasource after the SaveChangesAsync is completed? It won't show on the datasource until it completes.
1) The dependency graph is not picking up items which are still being loaded asynchronously
same as above. The asynchronous operation must be completed.
3) Doesn't like many to many relationships...
Based on the error message, it seems you are "crossing" entities between more than one entity manager. An entity can only belong to one entity manager. (when you import into a second entity manager, you actually have 2 copies of the same entity) Can you provide a test case reproducing this issue?
Below is a simple example (based on the example at http://drc.ideablade.com/xwiki/bin/view/Documentation/SavingBusinessObjects#HDependencyGraphRetrieval - http://drc.ideablade.com/xwiki/bin/view/Documentation/SavingBusinessObjects#HDependencyGraphRetrieval ) using multiple entity managers using async operations.
private void MainPage_Loaded(object sender, RoutedEventArgs e) {
NorthwindIBEntities em1 = new NorthwindIBEntities();
NorthwindIBEntities em2 = new NorthwindIBEntities();
int employeeID = 1;
var targetedEmployeesQuery = em1.Employees
.Where(emp => emp.EmployeeID == employeeID)
.Include("Orders.OrderDetails.Product");
var queryAsync = em1.ExecuteQueryAsync(targetedEmployeesQuery);
queryAsync.Completed += (q, queryArgs) => {
List<Employee> employees = new List<Employee>(queryArgs.Results);
Employee anEmployee = employees[0];
// Create roots list and add the employee.
List<Entity> roots = new List<Entity>();
em2.ImportEntities(new Entity[] { anEmployee }, MergeStrategy.OverwriteChanges);
//edit data on _em2
var myEditableEmployee = em2.Employees.With(QueryStrategy.CacheOnly).First();
myEditableEmployee.FirstName = ModifyString(myEditableEmployee.FirstName);
var op2 = em2.SaveChangesAsync();
op2.Completed += (s, savedArgs) => {
em1.ImportEntities(savedArgs.Entities, MergeStrategy.OverwriteChanges);
//checking if saved items successfully imported back to _em1
var myEmployeeBackToEM1 = em1.Employees.With(QueryStrategy.CacheOnly).First();
};
};
}
private String ModifyString(String temp) {
if (String.IsNullOrEmpty(temp)) {
return "X";
} else if (temp.EndsWith("X")) {
return temp.Substring(0, temp.Length - 1);
} else {
return temp + "X";
}
}
|