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


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

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


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

示例1: BuildSessionFactory

        public static IDictionary<string, ISessionFactory> BuildSessionFactory()
        {
           // var configure = new Configuration();
            var mapping = GetMappings();
            //configure.Configure();
            //configure.AddDeserializedMapping(mapping, "NHSchema");
            if (!CommonHelper.AllowMultiTenancy(out _ConnectionStringName))
            {
                var config = new Configuration();
                // config.SetInterceptor(new NHSQLInterceptor());
                config.Configure();
                var _host = EngineContext.Current.Resolve<HttpContextBase>().Request.Url.Authority;
                config.AddDeserializedMapping(mapping, "NHSchema");

                config.Configure()
                    .SetProperty(NHibernate.Cfg.Environment.ConnectionStringName, _ConnectionStringName)
                    .
                    SetProperty(NHibernate.Cfg.Environment.ShowSql, "true")
                    .SetProperty(NHibernate.Cfg.Environment.BatchSize, "0")
                    .SetProperty(NHibernate.Cfg.Environment.CacheRegionPrefix, _host);

                if (!_allFactories.ContainsKey(_host))
                    _allFactories.Add(_host, config.BuildSessionFactory());

            }
            else
            {
                XmlNodeList nodes = ConfigurationFile.GetElementsByTagName("Tenant");

                foreach (XmlNode n in nodes)
                {

                    var config = new Configuration();
                    // config.SetInterceptor(new NHSQLInterceptor());
                    config.Configure();

                    config.AddDeserializedMapping(mapping, "NHSchema");

                    config.Configure()
                        .SetProperty(NHibernate.Cfg.Environment.ConnectionString, n["ConnectionString"].InnerText)
                        .
                        SetProperty(NHibernate.Cfg.Environment.ShowSql, "true")
                        .SetProperty(NHibernate.Cfg.Environment.BatchSize, "0")
                        .SetProperty(NHibernate.Cfg.Environment.CacheRegionPrefix, n["HostName"].InnerText);
                    //  config.SetInterceptor(new NHSQLInterceptor());

                    if (!_allFactories.ContainsKey(n["HostName"].InnerText))
                        _allFactories.Add(n["HostName"].InnerText, config.BuildSessionFactory());

                }
            }
            return _allFactories;


        }
开发者ID:surifoll,项目名称:git-test,代码行数:55,代码来源:NHibernateConfigurator.cs

示例2: Main

 static void Main(string[] args)
 {
     NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
     cfg.Configure();
     NHibernate.Tool.hbm2ddl.SchemaExport schema = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);
     schema.Create(false, true);
 }
开发者ID:ssickles,项目名称:archive,代码行数:7,代码来源:Program.cs

示例3: CreateStatelessDbSession

        /// <summary>
        /// 创建StatelessDbSession对象
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="dbDialectProvider">数据库特性对象提供程序</param>
        /// <param name="mappingXml">实体关系映射配置Xml文本</param>
        /// <returns>返回StatelessDbSession对象</returns>
        public virtual StatelessDbSession CreateStatelessDbSession(string connectionString, IDbDialectProvider dbDialectProvider, string mappingXml)
        {
            ISessionFactory sf = null;
            while (!sessionFactories.TryGetValue(connectionString, out sf))
            {
                IDictionary<string, string> dbSetting = new Dictionary<string, string>
                {
                    ["dialect"] = dbDialectProvider.DialectName,
                    ["connection.connection_string"] = connectionString,
                };
                CustomizeNHSessionFactory(dbSetting);
                var x = new NHibernate.Cfg.Configuration();
                x = x.AddProperties(dbSetting);
                //允许采用配置文件修改NHibernate配置
                var hc = ConfigurationManager.GetSection(CfgXmlHelper.CfgSectionName) as NHibernate.Cfg.IHibernateConfiguration;
                if ((hc != null && hc.SessionFactory != null) || File.Exists(GetDefaultConfigurationFilePath()))
                {
                    x = x.Configure();
                }
                if (System.Transactions.Transaction.Current != null)
                {
                    //如果在分布式事务范围内,就将连接释放模式更改为on_close模式,防止auto模式下,重新获取连接,导致分布式事务升级
                    x.AddProperties(new Dictionary<string, string> {["connection.release_mode"] = "on_close" });
                }
                //添加实体关系映射
                if (!string.IsNullOrWhiteSpace(mappingXml))
                {
                    x.AddXml(mappingXml);
                }

                sf = x.BuildSessionFactory();
                sessionFactories.TryAdd(connectionString, sf);
            }
            return new StatelessDbSession(sf, connectionString);
        }
开发者ID:morowind,项目名称:BizCruiser,代码行数:42,代码来源:DbSessionFactory.cs

示例4: WorkWithOutSharedEngine

        public void WorkWithOutSharedEngine()
        {
            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            if (TestConfigurationHelper.hibernateConfigFile != null)
                cfg.Configure(TestConfigurationHelper.hibernateConfigFile);
            string[] mappings =
                new string[]
                    {
                        "Integration.Address.hbm.xml",
                        "Integration.Tv.hbm.xml",
                        "Integration.TvOwner.hbm.xml",
                        "Integration.Martian.hbm.xml",
                        "Integration.Music.hbm.xml"
                    };
            foreach (string file in mappings)
            {
                cfg.AddResource("NHibernate.Validator.Tests" + "." + file, Assembly.GetExecutingAssembly());
            }
            Environment.SharedEngineProvider = null;
            XmlConfiguration nhvc = new XmlConfiguration();
            nhvc.Properties[Environment.ApplyToDDL] = "true";
            nhvc.Properties[Environment.AutoregisterListeners] = "true";
            nhvc.Properties[Environment.ValidatorMode] = "UseAttribute";

            ValidatorInitializer.Initialize(cfg);
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:26,代码来源:ValidatorInitializerFixture.cs

示例5: ApplyWrongConstraint

        public void ApplyWrongConstraint()
        {
            XmlConfigurator.Configure();
            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            if (TestConfigurationHelper.hibernateConfigFile != null)
                cfg.Configure(TestConfigurationHelper.hibernateConfigFile);
            cfg.AddResource("NHibernate.Validator.Tests.Integration.WrongClass.whbm.xml", Assembly.GetExecutingAssembly());
            Environment.SharedEngineProvider = null;
            XmlConfiguration nhvc = new XmlConfiguration();
            nhvc.Properties[Environment.ApplyToDDL] = "true";
            nhvc.Properties[Environment.AutoregisterListeners] = "true";
            nhvc.Properties[Environment.ValidatorMode] = "UseAttribute";

            using (LoggerSpy ls = new LoggerSpy(typeof(ValidatorInitializer), Level.Warn))
            {
                ValidatorInitializer.Initialize(cfg);
                int found =
                    ls.GetOccurenceContaining(
                        string.Format("Unable to apply constraints on DDL for [MappedClass={0}]", typeof (WrongClass).FullName));
                Assert.AreEqual(1, found);
                found =
                    ls.GetOccurenceContaining(
                        string.Format("Unable to apply constraints on DDL for [MappedClass={0}]", typeof (WrongClass1).FullName));
                Assert.AreEqual(1, found);
            }
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:26,代码来源:ValidatorInitializerFixture.cs

示例6: NhibernateConfigurator

        protected NhibernateConfigurator(bool mapDtoAssembly)
        {
            var assembliesToMap = GetAssembliesToMap(mapDtoAssembly);
            var includeBaseTypes = GetIncludeBaseTypes();
            var ignoreBaseTypes = GetIgnoreBaseTypes();
            var discriminatedTypes = GetDiscriminatedTypes();
            var mapDefaultConventions = ShouldMapDefaultConventions();
            var assemblyWithAdditionalConventions = GetAssembliesWithAdditionalConventions();

            _configuration = new Configuration();
            _configuration.Configure();
            var autoPersistenceModel = AutoMap.Assemblies(new AutomappingConfiguration(discriminatedTypes.ToArray()), assembliesToMap);
            includeBaseTypes.Each(x => autoPersistenceModel.IncludeBase(x));
            ignoreBaseTypes.Each(x => autoPersistenceModel.IgnoreBase(x));
            assembliesToMap.Each(x => autoPersistenceModel.UseOverridesFromAssembly(x));
            if (mapDefaultConventions) autoPersistenceModel.Conventions.AddFromAssemblyOf<PrimaryKeyConvention>();
            assemblyWithAdditionalConventions.Each(x => autoPersistenceModel.Conventions.AddAssembly(x));

            _sessionFactory = Fluently.Configure(_configuration)
                .Mappings(x =>
                              {
                                  var mappingsContainer = x.AutoMappings.Add(autoPersistenceModel);
                                  var exportNhibernateMappingsFolder = ConfigurationManager.AppSettings["ExportNhibernateMappingsFolder"];
                                  if (!string.IsNullOrWhiteSpace(exportNhibernateMappingsFolder)) mappingsContainer.ExportTo(exportNhibernateMappingsFolder);
                              })
                .BuildSessionFactory();
        }
开发者ID:xhafan,项目名称:emailmaker,代码行数:27,代码来源:NhibernateConfigurator.cs

示例7: 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

示例8: 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

示例9: 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

示例10: GetDefaultConfiguration

 /// <summary>
 /// Standar Configuration for tests.
 /// </summary>
 /// <returns>The configuration using merge between App.Config and hibernate.cfg.xml if present.</returns>
 public static NHibernate.Cfg.Configuration GetDefaultConfiguration()
 {
     NHibernate.Cfg.Configuration result = new NHibernate.Cfg.Configuration();
     if (hibernateConfigFile != null)
         result.Configure(hibernateConfigFile);
     return result;
 }
开发者ID:spib,项目名称:nhcontrib,代码行数:11,代码来源:TestConfigurationHelper.cs

示例11: ConfigureNHibernate

 public NHibernate.Cfg.Configuration ConfigureNHibernate()
 {
     var cfg = new NHibernate.Cfg.Configuration();
     if (TestConfigurationHelper.hibernateConfigFile != null)
         cfg.Configure(TestConfigurationHelper.hibernateConfigFile);
     cfg.AddResource("NHibernate.Validator.Tests.Specifics.NHV82.Person.hbm.xml", Assembly.GetExecutingAssembly());
     return cfg;
 }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:8,代码来源:DdlForComponents.cs

示例12: 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

示例13: CreateDatabase

 /// <summary>
 /// Generate the database schema, apply it to the database and save the DDL used into a file.
 /// </summary>
 public static void CreateDatabase()
 {
     Configuration configuration = new Configuration();
     configuration.Configure();
     SchemaExport schemaExport = new SchemaExport(configuration);
     schemaExport.SetOutputFile("SQLite database schema.ddl");
     schemaExport.Create(true, true);
 }
开发者ID:rafidzal,项目名称:Sif3Framework-dotNet,代码行数:11,代码来源:DataFactory.cs

示例14: GetSessionFactory

 public static ISessionFactory GetSessionFactory()
 {
     var configuration = new NHibernate.Cfg.Configuration();
     configuration.Configure();
     configuration.AddAssembly(typeof(SessionFactoryFactory).Assembly.GetName().Name);
     log4net.Config.XmlConfigurator.Configure();
     var sessionFactory = configuration.BuildSessionFactory();
     return sessionFactory;
 }
开发者ID:lucidcoding,项目名称:EdaCalendarExample,代码行数:9,代码来源:SessionFactoryFactory.cs

示例15: InitializeSessionFactory

        private static ISessionFactory InitializeSessionFactory()
        {
            var cfg = new NHibernate.Cfg.Configuration();
            cfg.Configure();

            return Fluently.Configure(cfg)
                .Mappings(m => m.AutoMappings
                    .Add(CreateAutomappings))
                .BuildSessionFactory();
        }
开发者ID:jhlindell,项目名称:Lifebyte,代码行数:10,代码来源:SessionManager.cs


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