Beispiel #1
0
        public void ConstructGraph_Add_Save_Delete()
        {
            var loan = SaveNewLoan();

            using (var context = new LoanContext())
            {
                var foundLoan = context.Set <Loan>()
                                .Include(o => o.Lender)
                                .Include(o => o.LenderContact)
                                .SingleOrDefault(o => o.Id == loan.Id);
                foundLoan.ShouldNotBeNull();
                foundLoan.Log("Find", context);
                context.StateShouldBe(foundLoan, Unchanged);

                context.Remove(foundLoan);
                foundLoan.Log("Remove", context);
                context.StateShouldBe(foundLoan, Deleted);
                context.StateShouldBe(foundLoan.Lender, Unchanged); //  not cascading delete
                context.StateShouldBe(foundLoan.LenderContact, Unchanged);

                context.SaveChanges();
                foundLoan.Log("SaveChanged", context);
                context.StateShouldBe(foundLoan, Detached);
                context.StateShouldBe(foundLoan.Lender, Unchanged); //  not cascading delete
                context.StateShouldBe(foundLoan.LenderContact, Unchanged);
            }
        }
Beispiel #2
0
        public void Save_Find_Delete_SingleObject()
        {
            var thing = SaveNewThing();

            using (var context = new LoanContext())
            {
                var foundThing = context.Find <Thing>(thing.Id);
                foundThing.ShouldNotBeNull();
                foundThing.Log("Find", context);
                context.StateShouldBe(foundThing, Unchanged);

                context.Remove(foundThing);
                context.StateShouldBe(foundThing, Deleted);

                context.SaveChanges();
                context.StateShouldBe(foundThing, Detached);
            }
        }
Beispiel #3
0
 public async Task RemoveAsync(TEntity entity)
 {
     using LoanContext context = new LoanContext();
     context.Remove(entity);
     await context.SaveChangesAsync();
 }