EF Core add an entity without persisting it in the database

I have an EF Core application, which use Entity Framework as ORM. I am in the process of designing a system, which has a feature in which I need to add an entity without persisting it in the database right away. The feature entails the following "use-cases"

  1. User adds a new item (System should add the item and related entities without doing _context.SaveChanges();)
  2. User gets redirected to a new place where he can edit and save the item (actual persistence in the database happens when the item is saved)
  3. User discards the item or clicks away from the page (Nothing should be persisted in the database)

I was wondering, if there is a way in which I could achieve the above. More concrete, I'm looking for a way to save unique entities in my context, without doing _context.SaveChanges(); right away.

I want to do it in a way, so that I easily can persist it in the database, once the user decides to save his edits.

The, in my mind, patchy solution would be to just add the item, however, this will cause problems if the user just clicks away from the edit page. (I might end up having a ton of entities, which doesn't really contain anything)

The obvious choice would be to just add the entity once the save button is clicked - this doesn't however work in this context.


  • Is there a way in which I can construct unique database objects in my context that I can edit, without saving to the database right away.

I've read about sequences in EF core, and that may be a way to go?