本文整理汇总了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;
}
示例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());
});
}
示例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);
});
}