public static EntityEntry <TEntity> AddOrUpdate <TEntity>(this DbSet <TEntity> dbSet, ref TEntity entity, Expression <Func <TEntity, object> > expression) where TEntity : class { _context = _context ?? dbSet.GetContext(); if (EntityExists(_context, expression, ref entity)) { return(_context.Update(entity)); } else { return(_context.Add(entity)); } }
public static List <EntityEntry <TEntity> > AddOrUpdate <TEntity>(this DbSet <TEntity> dbSet, ref List <TEntity> entities, Expression <Func <TEntity, object> > expression) where TEntity : class { var entries = new List <EntityEntry <TEntity> >(); _context = _context ?? dbSet.GetContext(); for (int i = 0; i < entities.Count(); i++) { var entity = entities[i]; entries.Add(dbSet.AddOrUpdate(ref entity, expression)); entities[i] = entity; } return(entries); }