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


C# NHibernate.Cfg.Configuration.BuildSessionFactory方法代码示例

本文整理汇总了C#中NHibernate.Cfg.Configuration.BuildSessionFactory方法的典型用法代码示例。如果您正苦于以下问题:C# NHibernate.Cfg.Configuration.BuildSessionFactory方法的具体用法?C# NHibernate.Cfg.Configuration.BuildSessionFactory怎么用?C# NHibernate.Cfg.Configuration.BuildSessionFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NHibernate.Cfg.Configuration的用法示例。


在下文中一共展示了NHibernate.Cfg.Configuration.BuildSessionFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var iconFolderPath = ConfigurationManager.AppSettings["iconPath"];
            var dbFile = ConfigurationManager.AppSettings["dbPath"];

            var cfg = new NHibernate.Cfg.Configuration().Configure();
            var sessionFactory = cfg.BuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    Console.WriteLine("Building database tables");
                    new SchemaExport(cfg).Execute(false, true, false, session.Connection, null);
                    tx.Commit();
                }
                Console.WriteLine("Parsing XML in to memory database");
                new Schedule(ScheduleFile, iconFolderPath).Export(session);
            }
            Console.WriteLine("Saving memory database to disk");

            var tmpFile = Path.GetTempFileName();
            new BulkCopy(cfg, sessionFactory).Export(tmpFile, true);
            PersistentConnectionProvider.CloseDatabase();
            Console.WriteLine("Copying from temporary disk location to production.");
            File.Copy(tmpFile, dbFile, true);
            File.Delete(tmpFile);
            Console.WriteLine("All done. Press any key.");
            Console.ReadKey();
        }
开发者ID:jasondentler,项目名称:LivingRoom,代码行数:30,代码来源:Program.cs

示例2: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            var configuration = new NHibernate.Cfg.Configuration();
            configuration.Configure();
            configuration.AddAssembly(typeof(doCS.Models.Project).Assembly);
            SessionFactory = configuration.BuildSessionFactory();

            // Build up your application container and register your dependencies.
            var builder = new ContainerBuilder();
            builder.RegisterControllers(System.Reflection.Assembly.GetExecutingAssembly());
            builder.Register(x => SessionFactory.OpenSession()).As<ISession>().HttpRequestScoped();
            builder.RegisterType<doCS.Web.Helpers.Implimentation.ProjectContext>().As<doCS.Web.Helpers.IProjectContext>().HttpRequestScoped();

            //register extractor helpers
            builder.RegisterType<doCS.Web.Helpers.Implimentation.Extractor.ExtractorHelper>().As<doCS.Web.Helpers.IExtractorHelper>().HttpRequestScoped();
            builder.RegisterType<doCS.Web.Helpers.Implimentation.Extractor.ProjectUpdaterProvider>().InstancePerDependency();

            //register extractor dependencies
            builder.RegisterType<doCS.Extractor.Implementation.Extractor>().As<doCS.Extractor.IExtractor>().HttpRequestScoped();
            builder.RegisterType<doCS.Extractor.Implementation.DllExtractor>();
            builder.RegisterType<doCS.Extractor.Implementation.XmlExtractor>();

            //register view helpers
            builder.RegisterType<doCS.Web.ViewHelpers.XmlDocumentationHelper>();

            _containerProvider = new ContainerProvider(builder.Build());
            ControllerBuilder.Current.SetControllerFactory(new AutofacControllerFactory(ContainerProvider));

            SetupAutoMapper();
        }
开发者ID:flukus,项目名称:doCS,代码行数:34,代码来源:Global.asax.cs

示例3: InitSessionFactory

        public void InitSessionFactory()
        {
            try
            {
                string connectionString = "Data Source=Pets.sdf";
                string owner = String.Empty;

                NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration();
                configuration.Properties.Add("dialect", "NHibernate.Dialect.MsSqlCeDialect");
                configuration.Properties.Add("connection.driver_class", "NHibernate.Driver.SqlServerCeDriver");
                AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);

                configuration.Properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
                configuration.Properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
                configuration.Properties.Add("connection.connection_string", connectionString);
                configuration.Properties.Add("show_sql", "true");
                configuration.AddAssembly("DataDriver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");

                //ToDo :: Add more entity assembly keys if you nHibernate stuff crashes and you don't know why...

                _sessionFactory = configuration.BuildSessionFactory();
            }
            catch (Exception ex)
            {
                Trace.TraceInformation("Creating the session factory failed with {0}", ex.Message);
            }
        }
开发者ID:ssdug,项目名称:2013-April-Florey,代码行数:27,代码来源:MySessionFactory.cs

示例4: configTest

        public void configTest()
        {
            var cfg = new NHibernate.Cfg.Configuration().Configure("hibernate.cfg.xml");
            using (ISessionFactory sessionFactory = cfg.BuildSessionFactory()) {

            }
        }
开发者ID:zhangshuiyong,项目名称:TeachingManageSystem,代码行数:7,代码来源:ConfigUnitTest.cs

示例5: GetSessionFactoryFor

       /// <summary>
        /// This method attempts to find a session factory stored in <see cref="_sessionFactories" />
        /// via its name; if it can't be found it creates a new one and adds it the hashtable.
        /// </summary>
        /// <param name="sessionFactoryConfigPath">Path location of the factory config</param>
        public ISessionFactory GetSessionFactoryFor(string sessionFactoryConfigPath) {
            Check.Require(!string.IsNullOrEmpty(sessionFactoryConfigPath),
                "sessionFactoryConfigPath may not be null nor empty");

            //  Attempt to retrieve a stored SessionFactory from the hashtable.
            ISessionFactory sessionFactory = (ISessionFactory) _sessionFactories[sessionFactoryConfigPath];

            //  Failed to find a matching SessionFactory so make a new one.
            if (sessionFactory == null) {
                Check.Require(File.Exists(sessionFactoryConfigPath),
                    "The config file at '" + sessionFactoryConfigPath + "' could not be found");

                NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
                cfg.Configure(sessionFactoryConfigPath);

                //  Now that we have our Configuration object, create a new SessionFactory
                sessionFactory = cfg.BuildSessionFactory();

                if (sessionFactory == null) {
                    throw new InvalidOperationException("cfg.BuildSessionFactory() returned null.");
                }

                _sessionFactories.Add(sessionFactoryConfigPath, sessionFactory);
            }

            return sessionFactory;
        }
开发者ID:ericklombardo,项目名称:Nuaguil.Net,代码行数:32,代码来源:NHibernateSessionManager.cs

示例6: Main

        public static void Main(string[] args)
        {
            IList<Product> products;

            // Don't need to use schema export because of the hbm2dll property.
            var cfg = new NHibernate.Cfg.Configuration();
            cfg.Configure();
            // ensure that mapping hbm.xml file is loaded
            cfg.AddAssembly(typeof(MainClass).Assembly);

            Product p = new Product() {Name="Captains of Crush Gripper #1", Category="fitness" };

            ISessionFactory factory =
                cfg.BuildSessionFactory();

            using (ISession session = factory.OpenSession())
            {
                session.Save(p);
                session.Flush();

              	ICriteria sc = session.CreateCriteria<Product>();
              	products = sc.List<Product>();
                Console.WriteLine(products[0].Name);
              	session.Close();
            }
            factory.Close();

            Console.WriteLine( products.Count );

            Console.WriteLine ("Hello World!");
        }
开发者ID:I82Much,项目名称:Mono-NHibernate,代码行数:31,代码来源:Main.cs

示例7: Init

 public void Init()
 {
     //SystemController sys = (SystemController)Application["systemController"];
     var cfg = new NHibernate.Cfg.Configuration().Configure("hibernate.cfg.xml");
     sessionFactory = cfg.BuildSessionFactory();
     sys = new SystemController(sessionFactory);
 }
开发者ID:zhangshuiyong,项目名称:TeachingManageSystem,代码行数:7,代码来源:SystemControllerUnitTest.cs

示例8: SessionManager

        private SessionManager()
        {
            if (sessionFactory == null)
            {
                var configuration = new Configuration()
                    .AddAssembly(Assembly.GetExecutingAssembly())
                    .SetProperty("connection.connection_string", GetCoreConnectionString())
                    .Configure();

            //#if (DEBUG)
            //                {
                //var schemadrop = new SchemaExport(configuration);
                //schemadrop.Drop(true, false);

                //var schemaUpdate = new SchemaUpdate(configuration);

                //schemaUpdate.Execute(true, true);

                //var schemaCreate = new SchemaExport(configuration);
                //schemaCreate.Create(true, true);
            //                }
            //#endif

                sessionFactory = configuration.BuildSessionFactory();
            }
        }
开发者ID:RezaMahmood,项目名称:ChopShop,代码行数:26,代码来源:SessionManager.cs

示例9: NHibernateConfigurator

        public NHibernateConfigurator()
        {
            string conectionString = ConfigurationManager.ConnectionStrings.Cast<ConnectionStringSettings>().Last().ConnectionString;

            var configurationProperties = new Dictionary<string, string>
                {
                    {NHibernate.Cfg.Environment.Dialect, typeof (NHibernate.Dialect.PostgreSQL82Dialect).FullName},
                    {NHibernate.Cfg.Environment.ConnectionDriver, typeof (NHibernate.Driver.NpgsqlDriver).FullName},
                    {NHibernate.Cfg.Environment.ConnectionString, conectionString},
                };

            var assemblyWithEntities = Assembly.GetExecutingAssembly();

            var serializer = HbmSerializer.Default;
            serializer.Validate = true;

            MemoryStream hbmStream = serializer.Serialize(assemblyWithEntities);
            string hbmXml;
            using (var reader = new StreamReader(hbmStream))
            {
                hbmXml = reader.ReadToEnd();
            }

            var config = new Configuration()
                .SetProperties(configurationProperties)
                .Configure()  // add properties from app.config
                .AddXml(hbmXml);

            SessionFactory = config.BuildSessionFactory();
        }
开发者ID:energister,项目名称:NHibernateExample,代码行数:30,代码来源:NHibernateConfigurator.cs

示例10: Build

        /// <summary>
        /// Builds the session factory with the given properties. Database is updated if updateSchema is set
        /// </summary>
        /// <param name="nhibernateProperties"></param>
        /// <param name="updateSchema"></param>
        /// <returns></returns>
        public ISessionFactory Build(IDictionary<string, string> nhibernateProperties, bool updateSchema)
        {
            var scannedAssemblies = typesToScan.Select(t => t.Assembly).Distinct();

              var nhibernateConfiguration = new Configuration().SetProperties(nhibernateProperties);

              foreach (var assembly in scannedAssemblies)
            nhibernateConfiguration.AddAssembly(assembly);

              var mapping = new SagaModelMapper(typesToScan.Except(nhibernateConfiguration.ClassMappings.Select(x => x.MappedClass)));

              HackIdIntoMapping(mapping);

              nhibernateConfiguration.AddMapping(mapping.Compile());

              ApplyDefaultsTo(nhibernateConfiguration);

              if (updateSchema)
            UpdateDatabaseSchemaUsing(nhibernateConfiguration);

              try
              {
            return nhibernateConfiguration.BuildSessionFactory();
              }
              catch (Exception e)
              {
            if (e.InnerException != null)
              throw new ConfigurationErrorsException(e.InnerException.Message, e);

            throw;
              }
        }
开发者ID:kostaswonga,项目名称:NServiceBus,代码行数:38,代码来源:SessionFactoryBuilder.cs

示例11: Init

 public void Init()
 {
     //StudentController studentController = (StudentController)Session["studentController"];
     var cfg = new NHibernate.Cfg.Configuration().Configure("hibernate.cfg.xml");
     sessionFactory = cfg.BuildSessionFactory();
     studentController = new StudentController(sessionFactory);
 }
开发者ID:zhangshuiyong,项目名称:TeachingManageSystem,代码行数:7,代码来源:StudentControllerUnitTest.cs

示例12: GetSessionFactory

        public static NHibernate.ISessionFactory GetSessionFactory(
            string connectionString, List<String> DllNames)
        {
            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            // set provider & driver properties
            cfg.Properties.Add(
            "connection.provider",
                "NHibernate.Connection.DriverConnectionProvider");

            cfg.Properties.Add(
            "connection.driver_class",
                "NHibernate.Driver.SQLite20Driver");

            cfg.Properties.Add(
            "dialect",
                "NHibernate.Dialect.SQLiteDialect");

            cfg.Properties.Add(
            "max_fetch_depth","-1"); // allows for unlimited outer joins (recommeded value is maximum 4

            cfg.Properties.Add(
            "connection.connection_string",
                 ConfigurationManager.ConnectionStrings[connectionString].ConnectionString);

            cfg.Properties.Add("connection.isolation", "ReadCommitted");
            cfg.Properties.Add("query.substitutions", "true 1, false 0");

            // here we add all the needed assemblies that contain mappings or objects
            foreach (String assemblyName in DllNames)
                cfg.AddAssembly(System.Reflection.Assembly.Load(assemblyName));

            return cfg.BuildSessionFactory();
        }
开发者ID:zorky,项目名称:mymedias,代码行数:33,代码来源:NHIbernateSessionFactory.cs

示例13: Init

        /// <summary>
        /// initializes the session for database
        /// </summary>
        private static void Init()
        {
            NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();

            config.AddFile("db.cfg.xml");//adds all the embedded resources .hbm.xml
            config.AddFile("models.xml");
            sFactory = config.BuildSessionFactory();
        }
开发者ID:zakrzewiak7,项目名称:inzynieria,代码行数:11,代码来源:SessionFactory.cs

示例14: SessionManager

 private SessionManager()
 {
     Configuration config = new Configuration();
     config.Properties[NHibernate.Cfg.Environment.ConnectionString] =
         ConfigurationManager.ConnectionStrings["AtomicCms"].ConnectionString;
     config.Configure();
     this.sessionFactory = config.BuildSessionFactory();
 }
开发者ID:MasroorKhalid,项目名称:AtomicCms,代码行数:8,代码来源:SessionManager.cs

示例15: Application_Start

 protected void Application_Start(object sender, EventArgs e)
 {
     var cfg = new NHibernate.Cfg.Configuration().Configure(Server.MapPath("Config\\hibernate.cfg.xml"));
     NHibernate.ISessionFactory sessionFactory = cfg.BuildSessionFactory();
     Application.Add("sessionFactory", sessionFactory);
     SystemController sys = new SystemController((NHibernate.ISessionFactory)Application["sessionFactory"]);
     Application.Add("systemController", sys);
 }
开发者ID:zhangshuiyong,项目名称:TeachingManageSystem,代码行数:8,代码来源:Global.asax.cs


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