當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。