I would like to be able to locate newly-added EF Core entities without having to do a DbContext.SaveChanges() first (my desire stems from the fact that I'm adding entities recursively, and need access to newly-added entities in the child entities, and I'm looking to minimize database updates).
To put this in context, in the following pseudo-code entity2 will be null unless the commented line is uncommented:
var entity1 = DbContext.Assemblies
.FirstOrDefault( x => x.Name.Equals( assemName, StringComparison.OrdinalIgnoreCase ) );
if( entity1 == null )
{
entity1 = new AssemblyDb()
{
Name = assemName,
};
DbContext.Assemblies.Add( retVal );
//DbContext.SaveChanges();
}
var entity2 = dbUpdater.DbContext.Assemblies
.FirstOrDefault( x => x.Name.Equals( assemName, StringComparison.OrdinalIgnoreCase ) );
There is an SO discussion from years ago about this for Entity Framework here. I'm interested to see if there's a simple way of achieving the same end under EF Core.