예제 #1
0
 protected Thing SaveNewThing()
 {
     using (var context = new LoanContext())
     {
         var thing = new Thing();
         context.Update(thing);
         context.StateShouldBe(thing, Added);
         context.SaveChanges();
         context.StateShouldBe(thing, Unchanged);
         return(thing);
     }
 }
        public void Save_Linq_Include_Update_Graph()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            var xferLoan = SaveNewLoanExAndDetach();

            using (var context = new LoanContext())
            {
                // in case of Loan with childrenToo, this throws since Lender in graph twice
                context.Update(xferLoan);
                context.StateShouldBe(xferLoan, Modified);
            }
        }
예제 #3
0
        public void Save_Update_SingleObject()
        {
            var thing = SaveNewThing();

            using (var context = new LoanContext())
            {
                context.StateShouldBe(thing, Detached);
                context.Update(thing);
                context.StateShouldBe(thing, Modified);

                context.SaveChanges(); // will update db even no real changes
                context.StateShouldBe(thing, Unchanged);
            }
        }
예제 #4
0
        public void Save_Linq_Include_Update_Graph()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            var xferLoan = SaveNewLoanExAndDetach();

            using (var context = new LoanContext())
            {
                // for the analogous Loan test, this throws since Lender in graph twice
                context.Update(xferLoan);
                context.StateShouldBe(xferLoan, Modified);

                context.SaveChanges(); // updates only Loans since others null
                context.StateShouldBe(xferLoan, Unchanged);
            }
        }
예제 #5
0
        public void Save_Linq_Include_Update_Graph_Throw()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            var xferLoan = SaveNewLoanAndDetach();

            using (var context = new LoanContext())
            {
                try
                {
                    // throws since Attach in recursive and Lender is in graph twice
                    context.Update(xferLoan);
                    true.ShouldBeFalse();
                }
                catch (InvalidOperationException) {}
            }
        }
예제 #6
0
 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);
     }
 }
예제 #7
0
        public void Construct_Update_Save_SingleObject()
        {
            using (var context = new LoanContext())
            {
                var thing = new Thing();
                thing.Log("Constructed", context);
                context.StateShouldBe(thing, Detached);

                context.Update(thing);
                thing.Log("Updated", context);
                context.StateShouldBe(thing, Added);

                context.SaveChanges();
                thing.Log("SaveChanges", context);
                context.StateShouldBe(thing, Unchanged);
            }
        }
예제 #8
0
        public void Update_Thing()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            var thing = SaveNewThingAndDetach();

            using (var context = new LoanContext())
            {
                context.Update(thing);
                context.StateShouldBe(thing, Modified);

                thing.Name = "Peoria";
                context.StateShouldBe(thing, Modified);
                context.SaveChanges();
            }
            using (var context = new LoanContext())
            {
                thing = context.Set <Thing>().Find(thing.Id);
                thing.ShouldNotBeNull();
                thing.Name.ShouldBe("Peoria");
            }
        }
예제 #9
0
        public void ConstructGraph_Update_Save()
        {
            LogMsg(MethodBase.GetCurrentMethod().Name);
            using (var context = new LoanContext())
            {
                var loan = new Loan(childrenToo: true);
                loan.Log("Constructed", context);
                loan.Lender.ShouldNotBeNull();
                context.LoanGraphStateShouldBe(loan, Detached);

                context.Update(loan);
                loan.Log("Update after constructed", context);
                context.LoanGraphStateShouldBe(loan, Added);

                context.SaveChanges();
                loan.Log("SaveChanges", context);
                context.LoanGraphStateShouldBe(loan, Unchanged);
                context.LoanGraphStateShouldBe(loan, Unchanged);
                loan.Id.ShouldNotBe(Guid.Empty);
                loan.Lender.Id.ShouldNotBe(Guid.Empty);
                loan.LenderContact.Id.ShouldNotBe(Guid.Empty);
                loan.LenderContact.Lender.Id.ShouldBe(loan.Lender.Id);
            }
        }
예제 #10
0
 public async Task UpdateAsync(TEntity entity)
 {
     using LoanContext context = new LoanContext();
     context.Update(entity);
     await context.SaveChangesAsync();
 }