本文整理汇总了C#中ISession.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.BeginTransaction方法的具体用法?C# ISession.BeginTransaction怎么用?C# ISession.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.BeginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetModificationDateIntegrationTests
public SetModificationDateIntegrationTests()
{
listener = new SetModificationTimeFlushEntityEventListener()
{
CurrentDateTimeProvider = () => defaultDate
};
Configuration config = null;
sessionFactory = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory)
.Mappings(m =>
{
m.FluentMappings.Add<ThingMap>();
m.FluentMappings.Add<InheritedThingMap>();
m.FluentMappings.Add<RelatedThingMap>();
})
.ExposeConfiguration(cfg =>
{
listener.Register(cfg);
config = cfg;
})
.BuildSessionFactory();
session = sessionFactory.OpenSession();
using (var tx = session.BeginTransaction())
{
new SchemaExport(config).Execute(false, true, false, session.Connection, null);
tx.Commit();
}
session.BeginTransaction();
}
示例2: NHibernateTransaction
public NHibernateTransaction(ISession session, IsolationLevel? isolation = null)
{
Assertion.NotNull(session);
this.session = session;
this.transaction = isolation != null ? session.BeginTransaction(isolation.Value) : session.BeginTransaction();
this.isolation = isolation ?? IsolationLevel.Unspecified;
}
示例3: SessionUnitOfWork
public SessionUnitOfWork(ISession session, ILog log)
{
if (session == null)
{
throw Error.ArgumentNull("session");
}
if (log == null)
{
throw Error.ArgumentNull("log");
}
Session = session;
Log = log;
if (!Session.Transaction.IsActive)
{
Session.BeginTransaction();
IsInteract = true;
}
else
{
IsInteract = false;
}
}
示例4: Run
public void Run()
{
rng = new Random(376473672);
var sessionFactory = CreateSessionFactory();
// create properties
var properties = new NameValueCollection();
properties["level"] = "All";
using (session = sessionFactory.OpenSession())
{
using (var trans = session.BeginTransaction())
{
CreateProducts();
trans.Commit();
}
}
var customerCount = 30;
for (var i = 0; i < customerCount; i++)
{
using (session = sessionFactory.OpenSession())
{
using (var trans = session.BeginTransaction())
{
CreateCustomerWithOrders();
trans.Commit();
}
}
}
var pth = new TestPomonaHost(new Uri("http://localhost:4321/"), sessionFactory);
pth.Start();
Console.ReadLine();
pth.Stop();
}
示例5: UnitOfWork
public UnitOfWork(ISession session)
{
Guard.AgainstNull(() => session);
this.session = session;
this.transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);
}
示例6: NHibernateBlogService
public NHibernateBlogService(bool autoCommit)
{
AutoCommit = autoCommit;
_session = SessionFactory.OpenSession();
_transaction = _session.BeginTransaction();
}
示例7: Setup
public void Setup()
{
session = WindsorPersistenceFixture.Container.Resolve<ISession>();
repository = new SecurityRepository();
repository.Session = session;
tx = session.BeginTransaction();
}
示例8: SetUp
public void SetUp()
{
// new session on every test
Session = FixtureSetup.Container.Resolve<ISessionFactory>().OpenSession();
FixtureSetup.Container.Register(x => this.Session);
_transaction = Session.BeginTransaction();
}
示例9: SetUp
public void SetUp()
{
session = CreateSession();
session.BeginTransaction();
usrRep = new UserRepository(session);
repositorySetUp();
}
示例10: RebuildDatabase
public void RebuildDatabase()
{
ITransaction transaction = null;
try
{
var factoryFactory = new NHibernateSessionFactory();
ISessionFactory sessionFactory = factoryFactory.GetSessionFactory();
string[] dropScripts = factoryFactory.Configuration.GenerateDropSchemaScript(((ISessionFactoryImplementor)sessionFactory).Dialect);
string[] createScripts = factoryFactory.Configuration.GenerateSchemaCreationScript(((ISessionFactoryImplementor)sessionFactory).Dialect);
session = sessionFactory.OpenSession();
ExecuteScripts(dropScripts, session.Connection);
ExecuteScripts(createScripts, session.Connection);
SaveScripts(createScripts, "create.sql");
transaction = session.BeginTransaction();
var repository = new Repository(session);
var data = new Data();
data.Build(repository);
}
finally
{
if (session != null)
{
if (transaction != null && transaction.IsActive)
{
transaction.Commit();
}
session.Close();
session.Dispose();
}
}
}
示例11: Populate
private void Populate(ISession session)
{
Assert.IsNotNull(session);
session.BeginTransaction();
try
{
var person = new Person
{
FirstName = "brady",
LastName = "gaster"
};
session.Save(person);
Assert.Greater(person.Id, 0);
int newPersonId = person.Id;
person.FirstName = "Gina";
session.Update(person);
Assert.Greater(person.Id, 0);
Assert.IsTrue(person.Id == newPersonId);
session.Transaction.Commit();
}
catch
{
session.Transaction.Rollback();
}
}
示例12: BuyNewComputers
public bool BuyNewComputers(Computer[] cts)
{
bool bReturn = true;
try
{
session = sessionFactory.OpenSession();
tx = session.BeginTransaction();
for(int i=0;i<cts.Length;i++)
{
session.Save(cts[i]);
}
tx.Commit();
}
catch(Exception ex)
{
bReturn = false;
}
finally
{
session.Flush();
session.Disconnect();
}
return bReturn;
}
示例13: OnActionExecuting
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
DataSession = MvcApplication.SessionFactory.OpenSession();
DataSession.BeginTransaction();
base.OnActionExecuting(filterContext);
}
示例14: Transaction
public static void Transaction(ISession session, IsolationLevel level, Action transactional)
{
// If we are already in a transaction, don't start a new one
ITransaction tx = null;
if (session.Transaction.IsActive)
{
tx = session.Transaction;
}
else
{
tx = session.BeginTransaction(level);
}
try
{
transactional();
tx.Commit();
}
catch
{
tx.Rollback();
throw;
}
finally
{
tx.Dispose();
}
}
示例15: TemporaryReadonlySession
public TemporaryReadonlySession(ISessionFactory factory)
{
this.oldtemporary = AutomativeCurrentSessionContext.temporary;
Session = AutomativeCurrentSessionContext.temporary = factory.OpenSession();
Session.FlushMode = FlushMode.Never;
Session.BeginTransaction();
}