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


C# Configuration.OpenSession方法代码示例

本文整理汇总了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 ();
        }
开发者ID:smartinz,项目名称:randomhacking,代码行数:50,代码来源:Main.cs

示例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();
            }
        }
开发者ID:ronsher,项目名称:IntroToNHibernate,代码行数:27,代码来源:Program.cs

示例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();
        }
开发者ID:fr4nky80,项目名称:LearnCSharp,代码行数:14,代码来源:Program.cs

示例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;
        }
开发者ID:Elders,项目名称:Experiments,代码行数:23,代码来源:Program.cs


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