public TypePet Create(TypePet typePet)
        {
            //var petEntry = _ctx.Add(typePet);
            //_ctx.SaveChanges();
            //return petEntry.Entity;

            _ctx.Attach(typePet).State = EntityState.Added;
            _ctx.SaveChanges();
            return(typePet);
        }
예제 #2
0
        public Pet Create(Pet pet)
        {
            //code for tracking problem atach/detach when adding new object
            //foreach (var entry in _ctx.ChangeTracker.Entries())
            //    entry.State = EntityState.Detached;
            ////possible to create pet without owner, but not without type
            //if (pet.Owner != null)
            //    _ctx.Entry(pet.Owner).State = EntityState.Unchanged;
            //_ctx.Entry(pet.TypePet).State = EntityState.Unchanged;
            //_ctx.Add(pet);

            //var petEntry = _ctx.Add(pet);
            //_ctx.SaveChanges();
            //return petEntry.Entity;

            _ctx.Attach(pet).State = EntityState.Added;
            _ctx.SaveChanges();
            return(pet);
        }
예제 #3
0
        public Owner Create(Owner owner)
        {
            //    if (_ctx.Entry(owner.Pets).State == EntityState.Detached)
            //    {
            //        _ctx.Attach(owner.Pets).State = EntityState.Unchanged;
            //    }
            //    else
            //    {
            //        _ctx.Entry(owner.Pets).State = EntityState.Unchanged;
            //    }

            //_ctx.Attach(owner.Pets).State = EntityState.Unchanged;

            //var petEntry = _ctx.Add(owner);
            //_ctx.SaveChanges();
            //petEntry.State = EntityState.Detached;
            //return petEntry.Entity;

            _ctx.Attach(owner).State = EntityState.Added;
            _ctx.SaveChanges();
            return(owner);
        }
예제 #4
0
 public User Create(User user)
 {
     _ctx.Attach(user).State = EntityState.Added;
     _ctx.SaveChanges();
     return(user);
 }