Пример #1
0
        public Owner Update(Owner ownerUpdate)
        {
            _ctx.Attach(ownerUpdate).State = EntityState.Modified;
            _ctx.Entry(ownerUpdate).Collection(o => o.Pets).IsModified = true;
            var pets = _ctx.Pets.Where(p => p.Owner.Id == ownerUpdate.Id &&
                                       !ownerUpdate.Pets.Exists(po => po.Id == p.Id));

            foreach (var pet in pets)
            {
                pet.Owner = null;
                _ctx.Entry(pet).Reference(p => p.Owner).IsModified = true;
            }
            _ctx.SaveChanges();
            return(ownerUpdate);
        }
Пример #2
0
        public Pet Update(Pet petUpdate)
        {
            /*if (petUpdate.Owner != null && _ctx.ChangeTracker.Entries<Pet>().FirstOrDefault(oe => oe.Entity.Id == petUpdate.Owner.Id) == null)
             * {
             *  _ctx.Attach(petUpdate.Owner);
             * }
             * else
             * {
             *  _ctx.Entry(petUpdate).Reference(p => p.Owner).IsModified = true;
             * }
             * var updated = _ctx.Update(petUpdate).Entity;
             * _ctx.SaveChanges();*/

            _ctx.Attach(petUpdate).State = EntityState.Modified;
            _ctx.Entry(petUpdate).Reference(p => p.Owner).IsModified = true;
            _ctx.SaveChanges();
            return(petUpdate);
        }
Пример #3
0
 public void Edit(TodoItem entity)
 {
     db.Entry(entity).State = EntityState.Modified;
     db.SaveChanges();
 }