With its function ToList, the Entity Framework ObjectSet only displays stored entities. Consequently, when I call
after that (without calling SaveChanges)
myDataGrid.DataContext = context.Customers.ToList();
The newly created object is not shown in the DataGrid (despite
does not include it).
Is it possible to display these entities (those having
EntityState = Added
I appreciate it.
I believe you may get newly added entities that have not been stored by dialing:
var inserted = context.ObjectStateManager .GetObjectStateEntries(EntityState.Added) .Where(e => !e.IsRelationship) .Select(e => e.Entity) .OfType<Cutomer>();
However, based just on reading your inquiry, I'm afraid that you are attempting a mistake. Why is it necessary to merge retrieved and unsaved entities? Simply store it in your own distinct collection if you need to display unsaved stuff.
Please have a look at the TryGetObjectStateEntry(EntityKey, ObjectStateEntry) function.