public async Task AddAsync(Vehicle entity) { context.ChangeTracker.TrackGraph(entity, e => { if (e.Entry.IsKeySet) { e.Entry.State = EntityState.Unchanged; } else { e.Entry.State = EntityState.Added; } }); // context.Entry(entity.Owner).State = EntityState.Unchanged; LogState(entity); await context.Vehicles.AddAsync(entity); var entries = context.ChangeTracker.Entries().ToList(); LogState(entity); await context.SaveChangesAsync(); LogState(entity); }
public virtual async Task AddAsync(T entity) { entities.Add(entity); await context.SaveChangesAsync(); }