public virtual void Update(TEntity model, bool commit = true) { var entry = Context.Entry <TEntity>(model); if (entry.State == EntityState.Detached) { var set = Context.Set <TEntity>(); TEntity attachedEntity = set.Find(model.Id); // You need to have access to key if (attachedEntity != null) { var attachedEntry = Context.Entry(attachedEntity); attachedEntry.CurrentValues.SetValues(model); } else { entry.State = EntityState.Modified; // This should attach entity } } if (commit) { Context.SaveChanges(); } }
public bool IsCodeUnique(string Code, int id) { return(_Dbcontext.Set <City>().Any(x => x.Citycode == Code && x.CityId != id)); }
public BaseOperation(CountryDbContext context) { this.Context = context; this.DbSet = context.Set <TEntity>(); }
public bool IsCodeUnique(string Code, int id) { return(_Dbcontext.Set <State>().Any(x => x.Statecode == Code && x.StateId != id)); }