Пример #1
0
        protected virtual void Update <TBlog>(string navigation)
            where TBlog : class, IBlogAccesor, new()
        {
            DbContextHelpers.ExecuteWithStrategyInTransaction(CreateContext, UseTransaction,
                                                              context =>
            {
                var blogs = context.Set <TBlog>().ToList();

                foreach (var blog in blogs)
                {
                    context.Entry(blog).Collection(navigation).Load();

                    blog.AccessTitle += "Updated";

                    foreach (var post in blog.AccessPosts)
                    {
                        post.AccessTitle += "Updated";
                    }
                }

                AssertGraph(blogs, "Updated");

                context.SaveChanges();

                AssertGraph(blogs, "Updated");
            },
                                                              context =>
            {
                var blogs = context.Set <TBlog>().ToList();

                foreach (var blog in blogs)
                {
                    context.Entry(blog).Collection(navigation).Load();
                }

                AssertGraph(blogs, "Updated");
            });
        }
Пример #2
0
 protected virtual Task ExecuteWithStrategyInTransactionAsync(
     Func <UpdatesContext, Task> testOperation,
     Func <UpdatesContext, Task> nestedTestOperation1 = null)
 => DbContextHelpers.ExecuteWithStrategyInTransactionAsync(CreateContext, UseTransaction,
                                                           testOperation, nestedTestOperation1);
Пример #3
0
 protected virtual void ExecuteWithStrategyInTransaction(
     Action <UpdatesContext> testOperation,
     Action <UpdatesContext> nestedTestOperation1 = null)
 => DbContextHelpers.ExecuteWithStrategyInTransaction(CreateContext, UseTransaction,
                                                      testOperation, nestedTestOperation1);