EntityFramework show entities before saving changes

后端 未结 2 438
甜味超标
甜味超标 2020-12-20 14:48

Entity Framework ObjectSet with its method ToList shows just saved entities. That means, when I call

context.AddToCustomers(myNewCust);

and

2条回答
  •  天涯浪人
    2020-12-20 15:31

    I think you can get unsaved added entities by calling something like:

    var inserted = context.ObjectStateManager
                          .GetObjectStateEntries(EntityState.Added)
                          .Where(e => !e.IsRelationship)
                          .Select(e => e.Entity)
                          .OfType();
    

    But just by reading your question, I'm affraid that you are trying to do something wrong. Why do you need to combine unsaved entities with retrieved? If you need to show unsaved content you should simply keep it in your own separate collection.

提交回复
热议问题