EntityFramework show entities before saving changes

后端 未结 2 439
甜味超标
甜味超标 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<Cutomer>();
    

    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.

    0 讨论(0)
  • 2020-12-20 15:34

    Look at the TryGetObjectStateEntry(EntityKey, ObjectStateEntry) method

    http://msdn.microsoft.com/en-us/library/system.data.objects.objectstatemanager.aspx

    0 讨论(0)
提交回复
热议问题