本文整理汇总了C#中NHibernate.Cfg.Configuration.OpenSession方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.OpenSession方法的具体用法?C# Configuration.OpenSession怎么用?C# Configuration.OpenSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.OpenSession方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
Expense e = new Expense();
Provider p = new Provider(sessionFactory.OpenSession());
e = p.GetExpenseById(1);
e.Date = new DateTime(2009, 1, 18);
e.Description = "description";
e.Amount = 100;
//e.ExpenseTypeId = 1;
using(var session = sessionFactory.OpenSession())
using(session.BeginTransaction())
{
session.Save(e);
session.Transaction.Commit();
}
// Expense e = new Expense();
//
//
//
// Provider p = new Provider();
// e = p.GetExpenseById(1);
//
// Console.Write(e.Id);
// Console.Write(e.Description);
// Console.Write(e.Amount);
//
// Mono.Data.Sqlite.SqliteConnection conn = new Mono.Data.Sqlite.SqliteConnection("Data Source=database.sqlite3");
// Mono.Data.Sqlite.SqliteCommand cmd = new Mono.Data.Sqlite.SqliteCommand("select * from expenses", conn);
// conn.Open();
// Mono.Data.Sqlite.SqliteDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
// string s = "";
// while(rdr.Read())
// {
// s+=rdr.ToString();
// }
//
//
//
Application.Init ();
MainWindow win = new MainWindow ();
win.Show ();
Application.Run ();
}
示例2: Main
static void Main(string[] args)
{
// initialize profiler integration
NHibernateProfiler.Initialize();
try
{
// the session factory is the entry point to NHibernate
var sessionFactory = new Configuration()
.Configure("nhibernate.cfg.xml")
.BuildSessionFactory();
// the session is what we use to actually
using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
tx.Commit();
}
}
finally
{
// we need this so we wouldn't exit the process
// before all the work was sent to the profiler
ProfilerInfrastructure.FlushAllMessages();
}
}
示例3: SessionWithComplexTransactionsTest2
public void SessionWithComplexTransactionsTest2()
{
var SessionFactory = new Configuration().Configure()
//.SetNamingStrategy()
.BuildSessionFactory();
ISession session = SessionFactory.OpenSession();
CreateNewEntity(session);
//cats.Add(entity);
CreateNewEntity(session);
Console.WriteLine("Succeed!");
session.Flush();
}
示例4: Main
static void Main(string[] args)
{
var nhSessionFactory = new NHibernate.Cfg.Configuration()
// .AddAutoMappings()
.DropDatabaseTables()
.CreateDatabaseTables()
.BuildSessionFactory();
var start = DateTime.Now;
for (int i = 0; i < 100; i++)
{
using (var session = nhSessionFactory.OpenSession())
{
using (var tx = session.BeginTransaction())
{
tx.Commit();
}
}
}
var end = DateTime.Now;
int breaasd = 0;
}