当前位置: 首页>>代码示例>>C#>>正文


C# Repository.BeginTransaction方法代码示例

本文整理汇总了C#中Repository.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.BeginTransaction方法的具体用法?C# Repository.BeginTransaction怎么用?C# Repository.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Repository的用法示例。


在下文中一共展示了Repository.BeginTransaction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNextQuestion

        public Result GetNextQuestion()
        {
            if (this.Current == null || DateTime.Now > this.Expiry)
            {
                using (var repository = new Repository())
                {
                    repository.BeginTransaction();

                    var datapoint = repository.GetNextDatapoint();
                    if (datapoint == null)
                        return null;

                    repository.SetDatapointUsed(datapoint.ID);
                    var related = repository.GetRelatedDatapoints(datapoint.ID);

                    this.Current = new Result();
                    this.Current.Focus = datapoint;
                    this.Current.Related = related;

                    this.Expiry = DateTime.Now.AddSeconds(Constants.QuestionTimeout);

                    repository.CommitTransaction();
                }
            }

            this.Current.ExpiresIn = this.Expiry.Subtract(DateTime.Now).TotalSeconds;

            return this.Current;
        }
开发者ID:GoldyZ,项目名称:Who-is-Canberra,代码行数:29,代码来源:Game.cs

示例2: Invoke

        /// <summary>
        ///  Handle 'around' advice for services
        /// </summary>
        public object Invoke(IMethodInvocation invocation)
        {
            object returnValue = null;

            using (Repository repository = new Repository(Repository.SessionFactory))
            {
                repository.BeginTransaction();

                DomainRegistry.Repository = repository;
                DomainRegistry.Library = null;

                try
                {
                    returnValue = invocation.Proceed();

                    repository.CommitTransaction();
                }
                catch (Exception e)
                {
                    returnValue = ServiceResult.Error(invocation.Method.ReturnType, e);
                }
            }

            return returnValue;
        }
开发者ID:FlukeFan,项目名称:Atlanta,代码行数:28,代码来源:AopAroundAdvice.cs

示例3: Join_example_with_transaction_insert

        public void Join_example_with_transaction_insert()
        {
            Repository.DefaultConnectionString = @"Data source=.\SQLEXPRESS;Initial Catalog=WeenyMapper;Trusted_Connection=true";
            Repository.DefaultConvention = new BlogConvention();

            var myBlog = new Blog("My blog");

            var steve = new User("Steve", "password");

            var post1 = new BlogPost("Title 1", "Content 1 goes here") { Blog = myBlog, Author = steve };
            var post2 = new BlogPost("Title 2", "Content 2 goes here") { Blog = myBlog, Author = steve };
            var post3 = new BlogPost("Title 3", "Content 3 goes here") { Blog = myBlog, Author = steve };
            var post4 = new BlogPost("Title 4", "Content 4 goes here") { Blog = myBlog, Author = steve };

            using (var repository = new Repository())
            {
                using (var transaction = repository.BeginTransaction())
                {
                    repository.Insert(myBlog);
                    repository.Insert(steve);
                    repository.Insert(post1, post2, post3, post4);

                    transaction.Commit();
                }

                repository.Update<BlogPost>()
                          .Set(x => x.Title, "Updated title 2")
                          .Where(x => x.Id == post2.Id)
                          .Execute();

                repository.Delete<BlogPost>()
                          .Where(x => x.Id == post3.Id || x.Title == "Title 4")
                          .Execute();

                var actualBlog = repository.Find<Blog>().Where(x => x.Id == myBlog.Id)
                                           .Join(x => x.Posts, x => x.Blog)
                                           .OrderBy<BlogPost>(x => x.Title)
                                           .Execute();

                Assert.AreEqual("My blog", actualBlog.Name);
                Assert.AreEqual(2, actualBlog.Posts.Count);
                Assert.AreEqual("Title 1", actualBlog.Posts[0].Title);
                Assert.AreEqual("Updated title 2", actualBlog.Posts[1].Title);
            }
        }
开发者ID:erikojebo,项目名称:WeenyMapper,代码行数:45,代码来源:UsageExamples.cs

示例4: CreateBlogTestData

        private static void CreateBlogTestData()
        {
            Repository.DefaultConvention = new BlogConvention();

            var myBlog = new Blog("My blog");

            var steve = new User("Steve", "password");

            var post1 = new BlogPost("Title 1", "Content 1 goes here") { Blog = myBlog, Author = steve, PublishDate = new DateTime(2011, 1, 1) };
            var post2 = new BlogPost("Title 2", "Content 2 goes here") { Blog = myBlog, Author = steve, PublishDate = new DateTime(2012, 1, 5) };
            var post3 = new BlogPost("Title 3", "Content 3 goes here") { Blog = myBlog, Author = steve, PublishDate = new DateTime(2012, 4, 1) };
            var post4 = new BlogPost("Title 4", "Content 4 goes here") { Blog = myBlog, Author = steve, PublishDate = new DateTime(2013, 1, 1) };

            using (var repository = new Repository())
            {
                using (var transaction = repository.BeginTransaction())
                {
                    repository.Insert(myBlog);
                    repository.Insert(steve);
                    repository.Insert(post1, post2, post3, post4);

                    transaction.Commit();
                }
            }
        }
开发者ID:erikojebo,项目名称:WeenyMapper,代码行数:25,代码来源:UsageExamples.cs

示例5: Blog

        public void Transactions_are_not_rolled_back_if_already_rolled_back_from_exception_during_execution_of_a_SQL_statement()
        {
            var myBlog = new Blog("My blog");

            var post1 = new BlogPost("Title 1", "Content 1 goes here");

            using (var repository = new Repository())
            {

                try
                {
                    using (var transaction = repository.BeginTransaction())
                    {
                        repository.Insert(myBlog);

                        // Will throw exception due to foreign key constraints not being met
                        repository.Insert(post1);

                        transaction.Commit();
                    }
                }
                catch
                {
                   // Swallow the exception
                }

                var actualBlog = repository.Find<Blog>().Where(x => x.Name == "My blog").Execute();

                Assert.IsNull(actualBlog);
            }
        }
开发者ID:erikojebo,项目名称:WeenyMapper,代码行数:31,代码来源:RepositoryAcceptanceSpecs.cs


注:本文中的Repository.BeginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。