protected LoanEx SaveNewLoanEx() { using (var context = new LoanContext()) { var loan = new LoanEx(childrenToo: true); context.Update(loan); context.StateShouldBe(loan, Added); context.StateShouldBe(loan.Lender, Added); context.StateShouldBe(loan.LenderContact, Added); context.SaveChanges(); context.StateShouldBe(loan, Unchanged); context.StateShouldBe(loan.Lender, Unchanged); context.StateShouldBe(loan.LenderContact, Unchanged); return(loan); } }
protected LoanEx SaveNewLoanExAndDetach() { var loan = SaveNewLoanEx(); LoanEx xferLoan = null; using (var context = new LoanContext()) { var foundLoan = context.Set <LoanEx>() .SingleOrDefault(o => o.Id == loan.Id); foundLoan.ShouldNotBeNull(); foundLoan.Log("Find", context); context.StateShouldBe(foundLoan, Unchanged); foundLoan.LenderId.ShouldNotBeNull(); foundLoan.LenderContactId.ShouldNotBeNull(); xferLoan = JsonConvert.DeserializeObject <LoanEx>(JsonConvert.SerializeObject(foundLoan)); context.StateShouldBe(xferLoan, Detached); xferLoan.Log("After Deserialize", context); } return(xferLoan); }