public void Update(PersonDTO noteToSaveDTO) { //1. load existing entity and modify //var existingPerson = _personRepo.All().Single(); //var americanpassport = _passportRepo.Find(3); //existingPerson.Name = "Bush"; //existingPerson.Passport = americanpassport; //_personRepo.Update(existingPerson); //2. Eager load and attach the foreigh key //var existingPerson = _personRepo.TestEagerLoad(); //existingPerson.Name = "Bush"; //var passportEx = new Passport() {Id = 8}; //existing id //_passportRepo.Attach(passportEx); //existingPerson.Passport = passportEx; //_personRepo.Update(existingPerson); //3. Just attache the new entities with existing ids not working.. var person = new Person(); person.Id = 7; person.Name = "Bush"; _personRepo.Attach(person); var passport = new Passport() { Id = 8 }; _passportRepo.Attach(passport); person.Passport = passport; _personRepo.Update(person); _unitOfWork.Save(); }
public void Save(PersonDTO noteToSaveDTO) { var person = new Person(); person.InjectFrom(noteToSaveDTO); person.Passport = new Passport(); person.Passport.InjectFrom(noteToSaveDTO.PassportDTO); _personRepo.Add(person); _passportRepo.Add(new Passport(){ Number = "SCSCSCS", Nationality = "American"}); _unitOfWork.Save(); }