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


C# DbManager.Connect方法代码示例

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


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

示例1: TestSqlConnection_AddNewBookthenRollback_ReturnBookInitialCount

 private static int TestSqlConnection_AddNewBookthenRollback_ReturnBookInitialCount()
 {
     var dbManager = new DbManager<BooksContext>();
     var before = 0;
     dbManager.Connect(database =>
     {
         try
         {
             TransactionHelper.Begin(() =>
             {
                 before = database.Books.Count();
                 database.Books.Add(new Book
                 {
                     Name = "Test Book",
                     Isbn = "IKS9001F"
                 });
                 database.SaveChanges();
                 throw new Exception("Database offline! please try again later");
             });
         }
         catch (Exception ex)
         {
             throw new CustomException<DatabaseErrorExceptionArgs>(new DatabaseErrorExceptionArgs(ex.Message));
         }
     });
     return before;
 }
开发者ID:francis04j,项目名称:LayeredArchitecture,代码行数:27,代码来源:Transactional_Tests.cs

示例2: TruncateTable_Test

        public void TruncateTable_Test()
        {
            var connection = new DbManager<BloggingContext>();
            connection.Connect(database =>
            {
                var dbSet = database.Blogs;
                dbSet.RemoveRange(dbSet);
                database.SaveChanges();

                Assert.That(!dbSet.Any());
            });
        }
开发者ID:francis04j,项目名称:LayeredArchitecture,代码行数:12,代码来源:BloggingContext_Tests.cs

示例3: ThrowCustomException_DatabaseError_ConfirmRollBackSuccessful

        public void ThrowCustomException_DatabaseError_ConfirmRollBackSuccessful()
        {
            var dbManager = new DbManager<BooksContext>();

            var bookInitialCount = 0;

            //Cant use this as we need log4net 1.2.13 and that doesnt work with rhino service bus for some unknown reason.
            //            Assert.Throws<CustomException<DatabaseErrorExceptionArgs>>(() => before = TestSqlConnection_AddNewBookthenRollback_ReturnBookInitialCount());

            try
            {
                bookInitialCount = TestSqlConnection_AddNewBookthenRollback_ReturnBookInitialCount();
            }
            catch (Exception ex)
            {
                Assert.That(ex.GetType() == typeof (CustomException<DatabaseErrorExceptionArgs>));
            }

            dbManager.Connect(data =>
            {
                var after = data.Books.Count();
                Assert.That(bookInitialCount == after);
            });
        }
开发者ID:francis04j,项目名称:LayeredArchitecture,代码行数:24,代码来源:Transactional_Tests.cs


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