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


C# Configuration.DataBaseIntegration方法代码示例

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


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

示例1: Initialize

        public static void Initialize(TestContext context)
        {
            var cfg = new Configuration();
            cfg.DataBaseIntegration(x => {
                x.ConnectionString = "Server=localhost;Database=test;Uid=root;Pwd=kmn23po;";
                x.Driver<MySqlDataDriver>();
                x.Dialect<MySQLDialect>();
                x.LogSqlInConsole = true;
                x.BatchSize = 30;
            });

            var mapper = new ModelMapper();
            mapper.AddMapping<ParentMap>();
            mapper.AddMapping<ParentWithGuidMap>();
            mapper.AddMapping<ChildMap>();

            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            sessionFactory = cfg.BuildSessionFactory();

            var schemaUpdate = new SchemaUpdate(cfg);
            schemaUpdate.Execute(false, true);

            InsertData();
        }
开发者ID:jplindgren,项目名称:NHibernateCodeCheat,代码行数:25,代码来源:UnitTest1.cs

示例2: BuildSessionFactory

        private ISessionFactory BuildSessionFactory()
        {
            var mapper = new ModelMapper();
            var configuration = new Configuration();

            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

            configuration.DataBaseIntegration(c =>
            {
                c.ConnectionString = _connectionString;
                c.IsolationLevel = IsolationLevel.ReadCommitted;
                c.Driver<Sql2008ClientDriver>();
                c.Dialect<MsSql2008Dialect>();
                c.BatchSize = 50;
                c.Timeout = 30;

            #if DEBUG
                c.LogSqlInConsole = true;
                c.LogFormattedSql = true;
                c.AutoCommentSql = true;
            #endif
            });

            #if DEBUG
            configuration.SessionFactory().GenerateStatistics();
            #endif

            configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
            var sessionFactory = configuration.BuildSessionFactory();

            return sessionFactory;
        }
开发者ID:prabuw,项目名称:NHibernateTemplate,代码行数:32,代码来源:SessionFactoryFactory.cs

示例3: ConfigureNHibernate

		/// <summary>
		/// Configure NHibernate
		/// </summary>
		private static Configuration ConfigureNHibernate()
		{
			Configuration configure = new Configuration();
			configure.SessionFactoryName("SessionFactory");

			configure.DataBaseIntegration(db =>
				{
					db.Dialect<MsSql2008Dialect>();
					db.Driver<SqlClientDriver>();
					db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
					db.IsolationLevel = IsolationLevel.ReadCommitted;

					db.ConnectionStringName = RegtestingServerConfiguration.DefaultConnectionString;
					//db.Timeout = 10;

					//For testing
					//db.LogFormattedSql = true;
					//db.LogSqlInConsole = true;
					//db.AutoCommentSql = true;
				});

			HbmMapping hbmMapping = GetMappings();
			configure.AddDeserializedMapping(hbmMapping,"NHMapping");
			SchemaMetadataUpdater.QuoteTableAndColumns(configure);

			return configure;
		}
开发者ID:florianwittmann,项目名称:regtesting,代码行数:30,代码来源:ApplicationContext.cs

示例4: CreateSessionFactory

        /// <summary>
        /// Creates session factory
        /// </summary>
        /// <param name="configurationReader">configuration reader</param>
        /// <returns></returns>
        private static ISessionFactory CreateSessionFactory(IConfigurationReader configurationReader)
        {
            var configuration = new NHibernate.Cfg.Configuration();
            configuration.SessionFactoryName("Jumblocks Blog");

            configuration.DataBaseIntegration(db =>
            {
                db.Dialect<MsSql2008FixedDialect>();
                db.IsolationLevel = IsolationLevel.ReadCommitted;
                db.ConnectionString = configurationReader.ConnectionStrings["BlogDb"].ConnectionString;
                db.BatchSize = 100;

                //for testing
                db.LogFormattedSql = true;
                db.LogSqlInConsole = true;
                db.AutoCommentSql = true;
            });

            var mapper = new ModelMapper();
            mapper.AddMapping<BlogPostMap>();
            mapper.AddMapping<BlogUserMap>();
            mapper.AddMapping<ImageReferenceMap>();
            mapper.AddMapping<TagMap>();
            mapper.AddMapping<SeriesMap>();

            mapper.AddMapping<UserMap>();
            mapper.AddMapping<RoleMap>();
            mapper.AddMapping<OperationMap>();

            configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
            configuration.CurrentSessionContext<WebSessionContext>();

            return configuration.BuildSessionFactory();
        }
开发者ID:AndyCC,项目名称:Jumbleblocks-website,代码行数:39,代码来源:DatabaseSetup.cs

示例5: Mapping

		protected override void Mapping(Configuration config)
		{
			var mapper = new ModelMapper();
			mapper.Class<Software>(map =>
			{
				map.Id(s => s.Id, o => o.Generator(Generators.GuidComb));
				map.Property(s => s.Name, o =>
				{
					o.NotNullable(true);
					o.Unique(true);
				});
			});

			mapper.Class<AssignedSoftware>(map =>
			{
				map.Id(s => s.Key, o => o.Generator(Generators.Assigned));
				map.Property(s => s.Name, o =>
				{
					o.NotNullable(true);
					o.Unique(true);
				});
			});

			var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
			config.AddMapping(mapping);
			config.DataBaseIntegration(db => db.LogSqlInConsole = true);
		}
开发者ID:mzywitza,项目名称:Monastry.ActiveRecord,代码行数:27,代码来源:NhDaoFunctionalTests.cs

示例6: ConfigureNHibernate

        static Configuration ConfigureNHibernate()
        {
            var configure = new Configuration();
            configure.SessionFactoryName("HemArkivAccess");

            configure.DataBaseIntegration(db =>
            {
                db.Dialect<NHibernate.JetDriver.JetDialect>();
                db.Driver<NHibernate.JetDriver.JetDriver>();
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;

                db.ConnectionStringName = "HemArkivAccess";
                db.Timeout = 10;

                // enabled for testing
                db.LogFormattedSql = true;
                db.LogSqlInConsole = false;
                db.AutoCommentSql = false;
                db.Timeout = 10;
                //db.ConnectionProvider<NHibernate.Connection.DriverConnectionProvider>();
            });

            var mapping = GetMappings();
            configure.AddDeserializedMapping(mapping, "HemArkivAccess");

            return configure;
        }
开发者ID:marcusholmgren,项目名称:NHemarkiv,代码行数:27,代码来源:ConfigurationBuilder.cs

示例7: Main

        static void Main(string[] args)
        {
            var configuration = new Configuration();
            configuration.DataBaseIntegration(x =>
            {
                x.ConnectionString = "Server=localhost;Database=NHibernateSpike;Integerated Security=SSPI;";
                x.Driver<SqlClientDriver>();
                x.Dialect<MsSql2012Dialect>();
                x.LogSqlInConsole = true;
            });

            configuration.AddAssembly(Assembly.GetExecutingAssembly());

            var sessionFactory = configuration.BuildSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var customers = session.QueryOver<Customer>().Where(x => x.FirstName == "Oleg");
                    transaction.Commit();

                }

            }
        }
开发者ID:oshalygin,项目名称:NHibernateSpike,代码行数:26,代码来源:Program.cs

示例8: InMemoryNHibernateSessionSource

        public InMemoryNHibernateSessionSource(IEnumerable<Assembly> mappingAssemblies)
        {
            var configuration = new Configuration();
            configuration.DataBaseIntegration(cfg =>
                                              {
                                                  cfg.ConnectionString = "FullUri=file:memorydb.db?mode=memory&cache=shared";
                                                  cfg.Driver<SQLite20Driver>();
                                                  cfg.Dialect<SQLiteDialect>();
                                                  cfg.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                                                  cfg.SchemaAction = SchemaAutoAction.Update;
                                              });

            configuration.AddCodeMappingsFromAssemblies(mappingAssemblies);

            SchemaMetadataUpdater.QuoteTableAndColumns(configuration);

            _factory = configuration.BuildSessionFactory();

            _connectionCreatingSessionThatShouldNotBeDisposedUntilTestHasRunToEnd = _factory.OpenSession();
            _connection = _connectionCreatingSessionThatShouldNotBeDisposedUntilTestHasRunToEnd.Connection;

            new SchemaExport(configuration).Execute(
                              script: false,
                              export: true,
                              justDrop: false,
                              connection: _connection,
                              exportOutput: null);
        }
开发者ID:mlidbom,项目名称:Composable.Monolithic,代码行数:28,代码来源:InMemoryNHibernateSessionSource.cs

示例9: BuildConfiguration

        public Configuration BuildConfiguration(string connectionString, string sessionFactoryName)
        {
            Contract.Requires(!string.IsNullOrEmpty(connectionString), "ConnectionString is null or empty");
            Contract.Requires(!string.IsNullOrEmpty(sessionFactoryName), "SessionFactory name is null or empty");
            Contract.Requires(!string.IsNullOrEmpty(_databaseSchema), "Database Schema is null or empty");
            Contract.Requires(_configurator != null, "Configurator is null");

            return CatchExceptionHelper.TryCatchFunction(
                () =>
                {
                    DomainTypes = GetTypeOfEntities(_assemblies);

                    if (DomainTypes == null)
                        throw new Exception("Type of domains is null");

                    var configure = new Configuration();
                    configure.SessionFactoryName(sessionFactoryName);

                    configure.Proxy(p => p.ProxyFactoryFactory<ProxyFactoryFactory>());
                    configure.DataBaseIntegration(db => GetDatabaseIntegration(db, connectionString));

                    if (_configurator.GetAppSettingString("IsCreateNewDatabase").ConvertToBoolean())
                    {
                        configure.SetProperty("hbm2ddl.auto", "create-drop");
                    }

                    configure.Properties.Add("default_schema", _databaseSchema);
                    configure.AddDeserializedMapping(GetMapping(),
                                                     _configurator.GetAppSettingString("DocumentFileName"));

                    SchemaMetadataUpdater.QuoteTableAndColumns(configure);

                    return configure;
                }, Logger);
        }
开发者ID:ghy,项目名称:ConfORMSample,代码行数:35,代码来源:ConfORMConfigBuilder.cs

示例10: OpenSession

        public static ISession OpenSession()
        {
            if (sessionFactory == null)
            {
                System.Collections.Specialized.NameValueCollection sets = System.Configuration.ConfigurationManager.AppSettings;

                //获取连接字符串
                string server = Utilities.GetConfigValue("server");
                string pwd = VTMS.Common.Utilities.Base64Dencrypt(Utilities.GetConfigValue("DBPassword"));
                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
                connectionString = string.Format(connectionString, server, pwd);

                try
                {
                    Configuration cfg = new Configuration().Configure();
                    cfg.Proxy(p => p.ProxyFactoryFactory<NHibernate.Bytecode.DefaultProxyFactoryFactory>());
                    cfg.DataBaseIntegration(db =>
                    {
                        db.ConnectionString = connectionString;
                    });

                    sessionFactory = cfg.BuildSessionFactory();
                }
                catch (Exception e)
                {
                    VTMS.Common.MessageUtil.ShowError("无法登陆服务器,请检查服务器IP设置是否正确,错误信息为:" + e.Message);
                }
            }
            return sessionFactory.OpenSession();
        }
开发者ID:jilichao,项目名称:vtms,代码行数:30,代码来源:SessionFactory.cs

示例11: Configure

		protected override void Configure(Configuration configuration)
		{
			configuration.DataBaseIntegration(x =>
			{
				x.BatchSize = 10;
			});
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:7,代码来源:FixtureWithBatcher.cs

示例12: InitNHibernate

        private static void InitNHibernate()
        {
            lock (LockObject)
            {
                if (_sessionFactory == null)
                {
                    // Создание NHibernate-конфигурации приложения на основании описаний из web.config.
                    // После этого вызова, в том числе, из сборки будут извлечены настройки маппинга, 
                    // заданные в xml-файлах.
                    var configure = new Configuration().Configure();

                    // Настройка маппинга, созданного при помощи mapping-by-code
                    var mapper = new ModelMapper();
                    mapper.AddMappings(new List<Type>
                    {
                        // Перечень классов, описывающих маппинг
                        typeof (DocumentTypeMap),
                        typeof (DocumentMap),
                        typeof (DocumentWithVersionMap),
                    });
                    // Добавление маппинга, созданного при помощи mapping-by-code, 
                    // в NHibernate-конфигурацию приложения
                    configure.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), null);
                    //configure.LinqToHqlGeneratorsRegistry<CompareValuesGeneratorsRegistry>();
                    //configure.LinqToHqlGeneratorsRegistry<InGeneratorRegistry>();
                    configure.DataBaseIntegration(x =>
                    {
                        x.LogSqlInConsole = true;
                        x.LogFormattedSql = true;
                    });

                    _sessionFactory = configure.BuildSessionFactory();
                }
            }
        }
开发者ID:SergeyMironchuk,项目名称:NHibernateStudy,代码行数:35,代码来源:NHibernateHelper.cs

示例13: SessionFactory

        static SessionFactory()
        {
            var connectionString = @"Data Source=.\sqlexpress2014;Initial Catalog=BlogDatabase;Integrated Security=True";

            var configuration = new Configuration();
            configuration.DataBaseIntegration(
                x =>
                {
                    x.ConnectionString = connectionString;
                    x.Driver<SqlClientDriver>();
                    x.Dialect<MsSql2012Dialect>();
                });
            configuration.SetProperty(Environment.UseQueryCache, "true");
            configuration.SetProperty(Environment.UseSecondLevelCache, "true");
            configuration.SetProperty(Environment.CacheProvider, typeof(SysCacheProvider).AssemblyQualifiedName);
            var mapper = new ModelMapper();
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

            mapper.BeforeMapBag += (modelInspector, member1, propertyCustomizer) =>
            {
                propertyCustomizer.Inverse(true);
                propertyCustomizer.Cascade(Cascade.All | Cascade.DeleteOrphans);
            };
            mapper.BeforeMapManyToOne +=
                (modelInspector, member1, propertyCustomizer) => { propertyCustomizer.NotNullable(true); };
            mapper.BeforeMapProperty += (inspector, member, customizer) => customizer.NotNullable(true);
            var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
            configuration.AddMapping(mapping);
            sessionFactory = configuration.BuildSessionFactory();
        }
开发者ID:Nerielle,项目名称:Learning,代码行数:30,代码来源:SessionFactory.cs

示例14: TestEvent

        public void TestEvent()
        {
            var config = new NHibernate.Cfg.Configuration();
            config.Configure();
            config.DataBaseIntegration(db =>
            {
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
            });

            config.EventListeners.SaveEventListeners = new ISaveOrUpdateEventListener[] 
            { 
                new TestSaveOrUpdateEventListener()
            };

            config.AddDeserializedMapping(InternalHelper.GetAllMapper(), "Models");

            var factory = config.BuildSessionFactory();

            using (var session = factory.OpenSession())
            {
                session.Save(new Message() { Content = "Message1" });
                session.Flush();
            }

            using (var session = factory.OpenSession())
            {
                var message = session.Get<Message>(1);
                Assert.IsNotNull(message.Creator);
                Assert.AreEqual(message.LastEditor, "Leoli_SaveOrUpdate_Event");
            }
        }
开发者ID:leejulee,项目名称:NhibernateTest,代码行数:31,代码来源:UnitTestEvent.cs

示例15: BuildConfiguration

        public static Configuration BuildConfiguration(string connStr)
        {
            var cfg = new Configuration();

            // See http://fabiomaulo.blogspot.com/2009/07/nhibernate-configuration-through.html
            cfg.DataBaseIntegration(db => {
                db.Driver<SqlClientDriver>();
                db.Dialect<MsSql2012Dialect>();
                db.ConnectionString = connStr; // db.ConnectionStringName = "ConnStr";
                db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";

                // See http://geekswithblogs.net/lszk/archive/2011/07/12/showing-a-sql-generated-by-nhibernate-on-the-vs-build-in.aspx
                //db.LogSqlInConsole = true; // Remove if using Log4Net
                //db.LogFormattedSql = true;
                //db.AutoCommentSql = true;

                db.SchemaAction = SchemaAutoAction.Validate; // This correspond to "hbm2ddl.validate", see http://nhforge.org/blogs/nhibernate/archive/2008/11/23/nhibernate-hbm2ddl.aspx
            });

            var mapper = new ModelMapper();
            mapper.Class<Parent>(map => {
                map.Id(x => x.Id, m => {
                    m.Generator(Generators.GuidComb);
                    m.UnsavedValue(Guid.Empty);
                });
                map.Version(x => x.RowVersion, m => m.UnsavedValue(0));
                map.Property(x => x.Description);
            });
            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
            return cfg;
        }
开发者ID:gimmi,项目名称:randomhacking,代码行数:31,代码来源:NHibernateConfigurator.cs


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