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();
            }
        }
Ejemplo n.º 2
0
 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>();
 }
Ejemplo n.º 4
0
 public bool IsCodeUnique(string Code, int id)
 {
     return(_Dbcontext.Set <State>().Any(x => x.Statecode == Code && x.StateId != id));
 }