本文整理汇总了C#中Blog.GetCurrentSession方法的典型用法代码示例。如果您正苦于以下问题:C# Blog.GetCurrentSession方法的具体用法?C# Blog.GetCurrentSession怎么用?C# Blog.GetCurrentSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blog
的用法示例。
在下文中一共展示了Blog.GetCurrentSession方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBehaviour
private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode)
{
using (new SessionScope()) {
Post.DeleteAll();
Blog.DeleteAll();
}
var originalDefaultFlushType = AR.Holder.ConfigurationSource.DefaultFlushType;
try
{
AR.Holder.ConfigurationSource.Flush(flushType);
var blog = new Blog(); // just for CurrentSession
using (new SessionScope())
{
Blog.FindAll();
Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode);
using (new TransactionScope())
{
Blog.FindAll();
Assert.AreEqual(transactionScopeMode, blog.GetCurrentSession().FlushMode);
}
// Properly reset?
Blog.FindAll();
Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode);
}
}
finally
{
// Restore Default Flush type we corrupted before.
AR.Holder.ConfigurationSource.Flush(originalDefaultFlushType);
}
}
示例2: NestedTransactionScopesHaveCorrectTransactionContexts
public void NestedTransactionScopesHaveCorrectTransactionContexts()
{
using (new TransactionScope())
{
var blog1 = new Blog();
Blog.FindAll();
var s1 = blog1.GetCurrentSession();
var tx1 = s1.Transaction;
Assert.IsNotNull(tx1);
using (new TransactionScope())
{
var blog2 = new Blog();
Blog.FindAll();
var s2 = blog2.GetCurrentSession();
var tx2 = s2.Transaction;
Assert.IsNotNull(tx2);
Assert.AreNotSame(tx1, tx2);
// TransactionScope uses a new session!
Assert.AreNotSame(s1, s2);
}
using (new TransactionScope(TransactionMode.Inherits))
{
var blog3 = new Blog();
Blog.FindAll();
var tx3 = blog3.GetCurrentSession().Transaction;
Assert.IsNotNull(tx3);
Assert.AreSame(tx1, tx3);
}
Assert.IsTrue(tx1.IsActive);
}
using (new SessionScope())
{
var blog4 = new Blog();
Blog.FindAll();
using (new TransactionScope())
{
var blog5 = new Blog();
Assert.AreSame(blog4.GetCurrentSession().Transaction, blog5.GetCurrentSession().Transaction);
}
}
using (new SessionScope())
{
var blog6 = new Blog();
var session = blog6.GetCurrentSession();
Assert.IsNotNull(session.Transaction);
var tx4 = session.Transaction;
using (var tx5 = session.BeginTransaction())
{
Assert.AreSame(tx4, tx5);
Blog.FindAll();
using (var tx6 = session.BeginTransaction())
{
Assert.AreSame(tx5, tx6);
}
}
}
}