public virtual void Save() { try { _dbContext.SaveChanges(); } catch (DbUpdateConcurrencyException) { // for cases when we trying to update entities which does not present in database. var entries = _dbContext.ChangeTracker.Entries() .Where(i => i.State == EntityState.Modified); foreach (var entry in entries) { var dbValues = entry.GetDatabaseValues(); if (dbValues == null) { entry.State = EntityState.Added; } } _dbContext.SaveChanges(); } }
public virtual void Save() { _dbContext.SaveChanges(); }