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


C# Configuration.Initialize方法代码示例

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


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

示例1: Main

        private static void Main(string[] args)
        {
            XmlConfigurator.Configure();
            var log = LogManager.GetLogger(typeof (Program));

              SetupNHibernateValidator();

            var nhibernateConfig = new Configuration().Configure();
            nhibernateConfig.Initialize();

            ISessionFactory sessionFactory = nhibernateConfig.BuildSessionFactory();

            var schemaExport = new SchemaExport(nhibernateConfig);
            schemaExport.Execute(false, true, false);

            var junk = new Product
                       	{
                       		Name = "Spiffy Junk",
                       		Description = string.Empty,
                       		UnitPrice = -1M
                       	};

              var ve = Environment.SharedEngineProvider.GetEngine();
              var invalidValues = ve.Validate(junk);
              foreach (var invalidValue in invalidValues)
            log.InfoFormat("{0} {1}",
              invalidValue.PropertyName,
              invalidValue.Message);
        }
开发者ID:akhuang,项目名称:NHibernate,代码行数:29,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            XmlConfigurator.Configure();
              var log = LogManager.GetLogger(typeof(Program));

              SetupNHibernateValidator();

              var cfg = new Configuration().Configure();
              cfg.Initialize();

              var sessionFactory = cfg.BuildSessionFactory();

              var schemaExport = new SchemaExport(cfg);
              schemaExport.Execute(true, true, false);

              var junk = new Product
                   {
                     Name = "Spiffy Junk",
                     Description = "Stuff we can't sell.",
                     UnitPrice = -1M
                   };

              using (var session = sessionFactory.OpenSession())
              {
            using (var tx = session.BeginTransaction())
            {
              try
              {
            session.Save(junk);
            tx.Commit();
              }
              catch (InvalidStateException validationException)
              {
            var errors = validationException.GetInvalidValues();
            foreach (var error in errors)
              log.ErrorFormat("Error with property {0}: {1}",
                error.PropertyName, error.Message);
            tx.Rollback();
              }
            }
              }
        }
开发者ID:akhuang,项目名称:NHibernate,代码行数:42,代码来源:Program.cs

示例3: CreateSessionFactory

        private static ISessionFactory CreateSessionFactory(IKernel kernel)
        {
            var validatorEngine = kernel.Resolve<ValidatorEngine>();

            Assert.NotNull(typeof(System.Data.SQLite.SQLiteConnection));

            _nhConfig = new NHibernate.Cfg.Configuration()
                .SetProperty(NHibernate.Cfg.Environment.CurrentSessionContextClass, typeof(ConversationSessionContext).AssemblyQualifiedName)
                .SetProperty(Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName)
                .SetProperty(Environment.Dialect, typeof(SQLiteDialect).AssemblyQualifiedName)
                .SetProperty(Environment.ConnectionString, "Data Source=:memory:")
                .SetProperty(Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName)
                .SetProperty(Environment.ReleaseConnections, "on_close")
                .SetProperty(Environment.UseSecondLevelCache, "true")
                .SetProperty(Environment.UseQueryCache, "true")
                .SetProperty(Environment.CacheProvider, typeof(HashtableCacheProvider).AssemblyQualifiedName)
                .AddAssembly(typeof(User).Assembly);

            Security.Configure<User>(_nhConfig, SecurityTableStructure.Prefix);

            _nhConfig.Initialize(validatorEngine);
            return _nhConfig.BuildSessionFactory();
        }
开发者ID:nexida,项目名称:Rhino-Security-Administration,代码行数:23,代码来源:BaseTest.cs

示例4: ConfigureValidator

        /// <summary>
        /// Configura o validados do nhibernate para validar as classes do dominio
        /// </summary>
        /// <param name="nHibernateConfiguration"></param>
        /// <returns></returns>
        private static ValidatorEngine ConfigureValidator(Configuration nHibernateConfiguration)
        {
            var configure = new NHibernate.Validator.Cfg.Loquacious.FluentConfiguration();
            configure.Register(
                Assembly.GetExecutingAssembly().GetTypes()
                    .Where(t => t.Namespace != null && t.Namespace.Equals("Progas.Portal.Factory.Entity"))
                    .ValidationDefinitions())
                .SetDefaultValidatorMode(ValidatorMode.UseAttribute)
                .IntegrateWithNHibernate.ApplyingDDLConstraints().And.RegisteringListeners();

            var ve = new ValidatorEngine();
            ve.Configure(configure);
            nHibernateConfiguration.Initialize(ve);
            return ve;
        }
开发者ID:rafaelo4n,项目名称:Progas.Portal,代码行数:20,代码来源:SessionManager.cs

示例5: injectValidationAndFieldLengths

        private void injectValidationAndFieldLengths(Configuration nhConfig)
        {
            if (string.IsNullOrWhiteSpace(ValidationDefinitionsNamespace))
                return;

            MappingsValidatorEngine = new ValidatorEngine();
            var configuration = new FluentConfiguration();
            var validationDefinitions = MappingsAssembly.GetTypes()
                                                        .Where(t => t.Namespace == ValidationDefinitionsNamespace)
                                                        .ValidationDefinitions();
            configuration
                    .Register(validationDefinitions)
                    .SetDefaultValidatorMode(ValidatorMode.OverrideExternalWithAttribute)
                    .IntegrateWithNHibernate
                    .ApplyingDDLConstraints()
                    .And
                    .RegisteringListeners();
            MappingsValidatorEngine.Configure(configuration);

            //Registering of Listeners and DDL-applying here
            nhConfig.Initialize(MappingsValidatorEngine);
        }
开发者ID:yao-yi,项目名称:DNTProfiler,代码行数:22,代码来源:NHConfig.cs


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