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


C# Configuration.SessionFactory方法代码示例

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


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

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

示例2: TestFixtureSetUp

 public void TestFixtureSetUp()
 {
     configuration = new Configuration();
     configuration.SessionFactory()
                  .Integrate.Using<SQLiteDialect>()
                  .Connected.Using("Data source=testdb")
                  .AutoQuoteKeywords()
                  .LogSqlInConsole()
                  .EnableLogFormattedSql();
     var mapper = new ConventionModelMapper();
     mapper.Class<Foo>(cm => { });
     mapper.Class<Bar>(cm => { });
     CustomizeMapping(mapper);
     var mappingDocument = mapper.CompileMappingForAllExplicitlyAddedEntities();
     new XmlSerializer(typeof(HbmMapping)).Serialize(Console.Out, mappingDocument);
     configuration.AddDeserializedMapping(mappingDocument, "Mappings");
     new SchemaExport(configuration).Create(true, true);
     sessionFactory = configuration.BuildSessionFactory();
     using (var session = sessionFactory.OpenSession())
     using (var tx = session.BeginTransaction())
     {
         var foo = new Foo { Bars = CreateCollection() };
         foo.Bars.Add(new Bar { Data = 1 });
         foo.Bars.Add(new Bar { Data = 2 });
         id = session.Save(foo);
         tx.Commit();
     }
     sessionFactory.Statistics.IsStatisticsEnabled = true;
 }
开发者ID:polyzois,项目名称:NHibernate.Diegose,代码行数:29,代码来源:QueryableCollectionsFixture.cs

示例3: OracleSessionFactoryHelper

 static OracleSessionFactoryHelper()
 {
     var cfg = new Configuration();
     cfg.SessionFactory()
            .Proxy
                .DisableValidation()
                .Through<NHibernate.Bytecode.DefaultProxyFactoryFactory>()
                .Named("Fluent.SessionFactory")
                .GenerateStatistics()
                .Using(EntityMode.Poco)
                .ParsingHqlThrough<NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory>()
            .Integrate
                .Using<Oracle10gDialect>()
                .AutoQuoteKeywords()
                .LogSqlInConsole()
                .EnableLogFormattedSql()
            .Connected
                .Through<DriverConnectionProvider>()
                .By<OracleDataClientDriver>()
                .ByAppConfing("ConnectionString")
            .CreateCommands
                .Preparing()
                .WithTimeout(10)
                .AutoCommentingSql()
                .WithMaximumDepthOfOuterJoinFetching(11)
                .WithHqlToSqlSubstitutions("true 1, false 0, yes 'Y', no 'N'");
     SessionFactory = FluentNHibernate.Cfg.Fluently.Configure(cfg)
            .Database(OracleDataClientConfiguration.Oracle10.ShowSql())
            .Mappings(m => GetMappingsAssemblies().ToList()
                .ForEach(o => m.FluentMappings.AddFromAssembly(o))).BuildSessionFactory();
 }
开发者ID:chenchunwei,项目名称:Infrastructure,代码行数:31,代码来源:OracleSessionFactoryHelper.cs

示例4: CanSetDefaultFlushModeThroughLoquaciousConfiguration

		public void CanSetDefaultFlushModeThroughLoquaciousConfiguration()
		{
			var cfg = new Configuration()
				.Configure();

			cfg
				.SessionFactory()
				.DefaultFlushMode(FlushMode.Always);

			using (var sessionFactory = cfg.BuildSessionFactory())
			{
				using (var session = sessionFactory.OpenSession())
				{
					Assert.AreEqual(FlushMode.Always, session.FlushMode);
				}
			}

			cfg.Configure()
				.SessionFactory()
				.DefaultFlushMode(FlushMode.Commit);

			using (var sessionFactory = cfg.BuildSessionFactory())
			{
				using (var session = sessionFactory.OpenSession())
				{
					Assert.AreEqual(FlushMode.Commit, session.FlushMode);
				}
			}
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:29,代码来源:DefaultFlushModeFixture.cs

示例5: PrepareSessionFactory

        public void PrepareSessionFactory()
        {
            Configuration = new Configuration();
            Configuration.Proxy(p => p.ProxyFactoryFactory<ProxyFactoryFactory>())
                .DataBaseIntegration(db =>
                                         {
                                             db.ConnectionStringName = "db";
                                             db.Dialect<MsSql2008Dialect>();
                                         });
            Configuration.SetProperty("show_sql", "true");
            Configuration.SetDefaultAssembly("NHibernateDeepDive");
            Configuration.SetDefaultNamespace("NHibernate_Deep_Dive.Entities");
            Configuration.AddXmlFile("ClearDatabaseScript.hbm.xml");
            foreach (var mappingFile in Directory.GetFiles(MappingsDirectory))
            {
                Configuration.AddXmlFile(mappingFile);
            }
            AdjustConfiguration(Configuration);
            Configuration.SessionFactory().GenerateStatistics();

            SessionFactory = Configuration.BuildSessionFactory();

            //new SchemaExport(Configuration).Drop(false, true);
            new SchemaExport(Configuration).Execute(false, true, false);

            BeforeTestRun();
            PopulateDatabase();

            HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
        }
开发者ID:adymitruk,项目名称:NHibernate-Deep-Dive,代码行数:30,代码来源:SpecificationBase.cs

示例6: CreateConfiguration

        private Configuration CreateConfiguration(IKernel kernel)
        {
            var config = new Configuration()
                .Proxy(p => p.ProxyFactoryFactory<NHibernate.Bytecode.DefaultProxyFactoryFactory>());
#if DEBUG
            config.SessionFactory().GenerateStatistics();
#endif      
            return config;
        }
开发者ID:LodewijkSioen,项目名称:Sioen.Layerless,代码行数:9,代码来源:NHibernateInstaller.cs

示例7: GetSessionFactory

 public static ISessionFactory GetSessionFactory()
 {
     var config = new Configuration();
     config.SessionFactory().Integrate.Using<SQLiteDialect>().Connected.Using("Data source=nhtest.sqlite").AutoQuoteKeywords();
     var mapper = new ConventionModelMapper();
     Map(mapper);
     config.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "Mappings");
     SchemaMetadataUpdater.QuoteTableAndColumns(config);
     new SchemaUpdate(config).Execute(false, true);
     return config.BuildSessionFactory();
 }
开发者ID:diegose,项目名称:NHPad,代码行数:11,代码来源:Configurator.cs

示例8: GetSessionFactory

 public static ISessionFactory GetSessionFactory()
 {
     AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
     var config = new Configuration();
     //config.SessionFactory().Integrate.Using<SQLiteDialect>().Connected.Using("Data source=nhtest.sqlite").AutoQuoteKeywords();
     config.SessionFactory().Integrate.Using<SQLiteDialect>().Connected.Using(String.Format("Data source={0}", Path.Combine(clientPath, "nhtest.sqlite"))).AutoQuoteKeywords();
     var mapper = new ConventionModelMapper();
     Map(mapper);
     config.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "Mappings");
     SchemaMetadataUpdater.QuoteTableAndColumns(config);
     new SchemaUpdate(config).Execute(false, true);
     return config.BuildSessionFactory();
 }
开发者ID:marcoCasamento,项目名称:NHPad,代码行数:13,代码来源:Configurator.cs

示例9: TestFixtureSetUp

 public void TestFixtureSetUp()
 {
     var configuration = new Configuration();
     configuration.SessionFactory()
                  .Integrate.Using<SQLiteDialect>()
                  .Connected.Using("Data source=testdb")
                  .AutoQuoteKeywords()
                  .LogSqlInConsole()
                  .EnableLogFormattedSql();
     var mapper = new ConventionModelMapper();
     MapClasses(mapper);
     var mappingDocument = mapper.CompileMappingForAllExplicitlyAddedEntities();
     new XmlSerializer(typeof(HbmMapping)).Serialize(Console.Out, mappingDocument);
     configuration.AddDeserializedMapping(mappingDocument, "Mappings");
     new SchemaExport(configuration).Create(true, true);
     sessionFactory = configuration.BuildSessionFactory();
 }
开发者ID:polyzois,项目名称:NHibernate.Diegose,代码行数:17,代码来源:LocalDateFixture.cs

示例10: Configure

        private static Configuration Configure(Configuration self, string connectionString)
        {
            self.DataBaseIntegration(db =>
                                         {
                                             db.ConnectionString = connectionString;
                                             db.Driver<SQLite20Driver>();
                                             db.Dialect<SQLiteDialect>();
                                             db.LogFormattedSql = true;
                                             db.LogSqlInConsole = true;
                                             db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                                             db.SchemaAction = SchemaAutoAction.Recreate;
                                         });

            self.SessionFactory().GenerateStatistics();

            return self;
        }
开发者ID:solyutor,项目名称:enhima,代码行数:17,代码来源:Configurator.cs

示例11: DatabaseFactory

 public DatabaseFactory(ILoadBalanceScheduling loadBalanceScheduling)
 {
     //根据DbSnapInfo快照连接,创建ISessionFactory
     DbSnapInfo dbSnapInfo = loadBalanceScheduling.GetConnectDbSnap();
     Configuration cfg = new Configuration();
     cfg.SessionFactory().Integrate.Using<MsSql2008Dialect>().Connected.Using(dbSnapInfo.DbconnectString);
     //设置Mapping默认程序集 
     cfg.AddAssembly("Infrastructure.Data.MainBoundedContext");
     //设置proxyfactory
     cfg.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
     //设置缓存程序
     cfg.SetProperty("cache.provider_class", "NHibernate.Cache.HashtableCacheProvider");
     //启动二级缓存
     cfg.SetProperty("cache.use_second_level_cache", "true");
     //启动查询缓存
     cfg.SetProperty("cache.use_query_cache", "true");
     sessionFactory = cfg.BuildSessionFactory();
 }
开发者ID:lanfengqi,项目名称:DIC.2.0,代码行数:18,代码来源:DatabaseFactory.cs

示例12: BuildSessionFactory

        public static ISessionFactory BuildSessionFactory()
        {
            Configuration cfg = new Configuration();
            cfg.SessionFactory()
                .Integrate.Using<MsSql2008Dialect>()
                .Connected.Using(new SqlConnectionStringBuilder {
                        DataSource = @".\SQLEXPRESS",
                        InitialCatalog = "aspnet-webapi",
                        IntegratedSecurity = true
                    })
                .Schema.Updating();
            var mapper = new ModelMapper();
            mapper.AddMappings(typeof(ProductMap).Assembly.GetTypes()
                                                          .Where(t => t.Namespace != null && t.Namespace.StartsWith("webapi.Infrastructure.Mappings")));
            HbmMapping mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();

            cfg.AddMapping(mappings);
            return cfg.BuildSessionFactory();
        }
开发者ID:shahdatnext,项目名称:BlogSamples,代码行数:19,代码来源:NHibernateConfigurator.cs

示例13: Should_work_with_nhibernate

        public void Should_work_with_nhibernate()
        {
            Configuration configuration = new Configuration();
            configuration.SessionFactory()
                .Integrate.Using<SQLiteDialect>()
                .Connected.Using(new SQLiteConnectionStringBuilder{DataSource = ":memory:", Version = 3}).LogSqlInConsole();
            configuration.AddDeserializedMapping(DomainMapper.GetMappings(), "domain");

            using(var factory = configuration.BuildSessionFactory())
            {
                using(var session = factory.OpenSession())
                {
                    new SchemaExport(configuration).Execute(true, true, false, session.Connection, Console.Out);
                    ProductsCalculator productsCalculator = new ProductsCalculator(new Repository<Product>(session));
                    var price = productsCalculator.GetTotalPrice();

                    Assert.That(price, Is.EqualTo(0));
                }
            }
        }
开发者ID:shahdatnext,项目名称:BlogSamples,代码行数:20,代码来源:NHRepositoryTests.cs

示例14: Main

        static void Main()
        {
            NHibernateProfiler.Initialize();

            var cfg = new Configuration();
            cfg.DataBaseIntegration(x =>
                                        {
                                            x.ConnectionStringName = "scratch";
                                            x.Driver<SqlClientDriver>();
                                            x.Dialect<MsSql2008Dialect>();
                                        });
            cfg.SessionFactory().GenerateStatistics();
            cfg.AddAssembly(typeof (Program).Assembly);

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

            var sessionFactory = cfg.BuildSessionFactory();
            using(var session = sessionFactory.OpenSession())
            using(var tx = session.BeginTransaction())
            {
                var module = new Module { ModuleCode = new ModuleCode { Value = "class Foo; end;" } };
                session.Save(module);
                tx.Commit();
            }
            using(var session = sessionFactory.OpenSession())
            using(var tx = session.BeginTransaction())
            {
                var module = session.QueryOver<Module>().List().First();
                Console.WriteLine(module.ModuleXml);
            //                Console.WriteLine(module.ModuleCode);
            //                Console.WriteLine(module.ModuleXml);
                tx.Commit();
            }
            Console.WriteLine("Press <ENTER> to exit...");
            Console.ReadLine();
        }
开发者ID:JamesKovacs,项目名称:NHibernateCourseMaterials,代码行数:37,代码来源:Program.cs

示例15: CompleteConfiguration

		public void CompleteConfiguration()
		{
			// Here I'm configuring near all properties outside the scope of Configuration class
			// Using the Configuration class the user can add mappings and configure listeners
			var cfg = new Configuration();
			cfg.SessionFactory().Named("SomeName")
				.Caching
					.Through<HashtableCacheProvider>()
					.PrefixingRegionsWith("xyz")
					.Queries
						.Through<StandardQueryCache>()
					.UsingMinimalPuts()
					.WithDefaultExpiration(15)
				.GeneratingCollections
					.Through<DefaultCollectionTypeFactory>()
				.Proxy
					.DisableValidation()
					.Through<ProxyFactoryFactory>()
				.ParsingHqlThrough<ClassicQueryTranslatorFactory>()
				.Mapping
					.UsingDefaultCatalog("MyCatalog")
					.UsingDefaultSchema("MySche")
				.Integrate
					.Using<MsSql2000Dialect>()
					.AutoQuoteKeywords()
					.BatchingQueries
						.Through<SqlClientBatchingBatcherFactory>()
						.Each(15)
					.Connected
						.Through<DebugConnectionProvider>()
						.By<SqlClientDriver>()
						.Releasing(ConnectionReleaseMode.AfterTransaction)
						.With(IsolationLevel.ReadCommitted)
						.Using("The connection string")
					.CreateCommands
						.AutoCommentingSql()
						.ConvertingExceptionsThrough<SQLStateConverter>()
						.Preparing()
						.WithTimeout(10)
						.WithMaximumDepthOfOuterJoinFetching(11)
						.WithHqlToSqlSubstitutions("true 1, false 0, yes 'Y', no 'N'")
					.Schema
						.Validating()
			;

			Assert.That(cfg.Properties[Environment.SessionFactoryName], Is.EqualTo("SomeName"));
			Assert.That(cfg.Properties[Environment.CacheProvider],
									Is.EqualTo(typeof(HashtableCacheProvider).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.CacheRegionPrefix], Is.EqualTo("xyz"));
			Assert.That(cfg.Properties[Environment.QueryCacheFactory],
									Is.EqualTo(typeof(StandardQueryCache).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.UseMinimalPuts], Is.EqualTo("true"));
			Assert.That(cfg.Properties[Environment.CacheDefaultExpiration], Is.EqualTo("15"));
			Assert.That(cfg.Properties[Environment.CollectionTypeFactoryClass],
									Is.EqualTo(typeof(DefaultCollectionTypeFactory).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.UseProxyValidator], Is.EqualTo("false"));
			Assert.That(cfg.Properties[Environment.ProxyFactoryFactoryClass],
						Is.EqualTo(typeof(ProxyFactoryFactory).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.QueryTranslator],
						Is.EqualTo(typeof(ClassicQueryTranslatorFactory).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.DefaultCatalog], Is.EqualTo("MyCatalog"));
			Assert.That(cfg.Properties[Environment.DefaultSchema], Is.EqualTo("MySche"));
			Assert.That(cfg.Properties[Environment.Dialect],
						Is.EqualTo(typeof(MsSql2000Dialect).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.Hbm2ddlKeyWords], Is.EqualTo("auto-quote"));
			Assert.That(cfg.Properties[Environment.BatchStrategy],
						Is.EqualTo(typeof(SqlClientBatchingBatcherFactory).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.BatchSize], Is.EqualTo("15"));
			Assert.That(cfg.Properties[Environment.ConnectionProvider],
						Is.EqualTo(typeof(DebugConnectionProvider).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.ConnectionDriver],
						Is.EqualTo(typeof(SqlClientDriver).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.ReleaseConnections],
			            Is.EqualTo(ConnectionReleaseModeParser.ToString(ConnectionReleaseMode.AfterTransaction)));
			Assert.That(cfg.Properties[Environment.Isolation], Is.EqualTo("ReadCommitted"));
			Assert.That(cfg.Properties[Environment.ConnectionString], Is.EqualTo("The connection string"));
			Assert.That(cfg.Properties[Environment.UseSqlComments], Is.EqualTo("true"));
			Assert.That(cfg.Properties[Environment.SqlExceptionConverter],
									Is.EqualTo(typeof(SQLStateConverter).AssemblyQualifiedName));
			Assert.That(cfg.Properties[Environment.PrepareSql], Is.EqualTo("true"));
			Assert.That(cfg.Properties[Environment.CommandTimeout], Is.EqualTo("10"));
			Assert.That(cfg.Properties[Environment.MaxFetchDepth], Is.EqualTo("11"));
			Assert.That(cfg.Properties[Environment.QuerySubstitutions], Is.EqualTo("true 1, false 0, yes 'Y', no 'N'"));
			Assert.That(cfg.Properties[Environment.Hbm2ddlAuto], Is.EqualTo("validate"));
		}
开发者ID:paulbatum,项目名称:nhibernate,代码行数:85,代码来源:ConfigurationFixture.cs


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