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


C# Configuration.Cache方法代码示例

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


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

示例1: PostProcessConfiguration

        /// <summary>
        /// 
        /// </summary>
        /// <param name="config"></param>
        protected override void PostProcessConfiguration(Configuration config)
        {
            if (FluentNhibernateMappingAssemblies != null)
            {
                foreach (var assemblyName in FluentNhibernateMappingAssemblies)
                {
                    config.AddMappingsFromAssembly(Assembly.Load(assemblyName));
                }
            }

            config.Properties.Add("nhibernate.envers.KotikoBlog_with_modified_flag", "true");
                //log property data for revisions
            config.IntegrateWithEnvers(new AttributeConfiguration());
            config.SetListener(ListenerType.PreInsert, new KotikoBlogAuditEventListener());
            config.SetListener(ListenerType.PreUpdate, new KotikoBlogAuditEventListener());
            config.SetListener(ListenerType.PreDelete, new KotikoBlogAuditEventListener());
            config.SetListener(ListenerType.PreCollectionRecreate, new KotikoBlogAuditEventListener());
            config.SetListener(ListenerType.PreCollectionUpdate, new KotikoBlogAuditEventListener());
            config.SetListener(ListenerType.PreCollectionRemove, new KotikoBlogAuditEventListener());
            config.Cache(c =>
            {
                c.UseMinimalPuts = true;
                c.UseQueryCache = true;
                c.Provider<SysCacheProvider>();
            });
        }
开发者ID:truller2010,项目名称:KotikoBlog,代码行数:30,代码来源:FluentNhibernateLocalSessionFactoryObject.cs

示例2: Apply

		public virtual void Apply(Configuration configuration, IDatabaseProvider databaseProvider)
		{
			configuration.CurrentSessionContext<CallSessionContext>();

			configuration.DataBaseIntegration(db => SetDatabase(db, databaseProvider, configuration));

			configuration.Cache(SetCache);

			configuration.Proxy(SetProxy);
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:10,代码来源:DefaultConfiguration.cs

示例3: BuildSessionFactory

        private ISessionFactory BuildSessionFactory()
        {
            var configuration = new Configuration();
            configuration.DataBaseIntegration(db =>
            {
                db.Dialect<MsSql2008Dialect>();
                db.ConnectionStringName = "NHibernate_CRUD";
            });
            configuration.Properties[Environment.CurrentSessionContextClass]
                            = typeof(LazySessionContext).AssemblyQualifiedName;

            configuration.Cache(c => c.UseQueryCache = false);

            configuration.Proxy(p => p.ProxyFactoryFactory<ProxyFactoryFactory>());

            configuration.AddAssembly(GetType().Assembly);

            return configuration.BuildSessionFactory();
        }
开发者ID:CezaryRynkowski,项目名称:NHibernateMVC,代码行数:19,代码来源:NHibernateInstaller.cs

示例4: CreateSessionFactory

        internal static ISessionFactory CreateSessionFactory()
        {
            string connectionString = ConnectionString;

            ModelMapper mapper = new ModelMapper();
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
            //mapper.BeforeMapSet += (mi, t, map) =>
            //{
            //    map.BatchSize(20);
            //    map.Cascade(Cascade.All | Cascade.DeleteOrphans);
            //};
            HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            var configuration = new Configuration();
            configuration.DataBaseIntegration(c =>
            {
                c.Dialect<MsSqlCe40Dialect>();
                c.ConnectionString = connectionString;
                c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                c.BatchSize = 25;
                //c.SchemaAction = SchemaAutoAction.Update;
            });
            configuration.Cache(c =>
            {
                //c.Provider<NHibernate.Caches.SysCache.SysCacheProvider>();
                c.UseQueryCache = true;
                c.DefaultExpiration = 10000;
            });
            configuration.AddMapping(domainMapping);

            try
            {
                return configuration.BuildSessionFactory();
            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:ThomasSchmidt,项目名称:MixedStuff,代码行数:39,代码来源:BlogDbContext.cs

示例5: FullConfiguration

		public void FullConfiguration()
		{
			var configure = new Configuration();
			configure.SessionFactoryName("SomeName");
			configure.Cache(c =>
												{
													c.UseMinimalPuts = true;
													c.DefaultExpiration = 15;
													c.RegionsPrefix = "xyz";
													c.Provider<HashtableCacheProvider>();
													c.QueryCache<StandardQueryCache>();
												});
			configure.CollectionTypeFactory<DefaultCollectionTypeFactory>();
			configure.HqlQueryTranslator<ClassicQueryTranslatorFactory>();
			configure.LinqToHqlGeneratorsRegistry<DefaultLinqToHqlGeneratorsRegistry>();
			configure.Proxy(p =>
												{
													p.Validation = false;
													p.ProxyFactoryFactory<DefaultProxyFactoryFactory>();
												});
			configure.Mappings(m=>
			                   	{
			                   		m.DefaultCatalog = "MyCatalog";
			                   		m.DefaultSchema = "MySche";
			                   	});
			configure.DataBaseIntegration(db =>
			                              	{
			                              		db.Dialect<MsSql2000Dialect>();
			                              		db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
			                              		db.Batcher<SqlClientBatchingBatcherFactory>();
			                              		db.BatchSize = 15;
			                              		db.ConnectionProvider<DebugConnectionProvider>();
			                              		db.Driver<SqlClientDriver>();
			                              		db.ConnectionReleaseMode = ConnectionReleaseMode.AfterTransaction;
			                              		db.IsolationLevel = IsolationLevel.ReadCommitted;
			                              		db.ConnectionString = "The connection string";
			                              		db.AutoCommentSql = true;
			                              		db.ExceptionConverter<SQLStateConverter>();
			                              		db.PrepareCommands = true;
			                              		db.Timeout = 10;
			                              		db.MaximumDepthOfOuterJoinFetching = 11;
			                              		db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";
			                              		db.SchemaAction = SchemaAutoAction.Validate;
			                              	});

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

示例6: BuildSessionFactory

        public static NHibernate.ISessionFactory BuildSessionFactory(bool useUnitTest = false)
        {
            var mapper = new NHibernate.Mapping.ByCode.ConventionModelMapper();


            mapper.IsEntity((t, declared) => t.Namespace == "Domain");

            mapper.BeforeMapClass += mapper_BeforeMapClass;
            mapper.BeforeMapProperty += mapper_BeforeMapProperty;
            mapper.BeforeMapManyToOne += mapper_BeforeMapManyToOne;            
            mapper.BeforeMapBag += mapper_BeforeMapBag;

            var cfg = new NHibernate.Cfg.Configuration();



            // .DatabaseIntegration! Y U EXTENSION METHOD?!
            cfg.DataBaseIntegration(c =>
            {
                var cs = System.Configuration.ConfigurationManager.ConnectionStrings["TheSpaConnection"].ConnectionString;


                // SQL Server
                c.Driver<NHibernate.Driver.SqlClientDriver>();
                c.Dialect<NHibernate.Dialect.MsSql2008Dialect>();
                c.ConnectionString = "Server=.;Database=SpaArchitectureMvp;Trusted_Connection=True";

                //// PostgreSQL                
                //c.Driver<NHibernate.Driver.NpgsqlDriver>();
                //c.Dialect<NHibernate.Dialect.PostgreSQLDialect>();
                //c.ConnectionString = cs;

                if (useUnitTest)
                {
                    c.LogSqlInConsole = true;
                    c.LogFormattedSql = true;
                }
            });


            System.Collections.Generic.IEnumerable<System.Type> entities = typeof(Domain.PersonDomain.Person).Assembly.GetExportedTypes()
                .Where(x => !(x.IsAbstract && x.IsSealed)); // exclude static 



            NHibernate.Cfg.MappingSchema.HbmMapping mapping = mapper.CompileMappingFor(entities);

            cfg.AddMapping(mapping);


            // http://www.ienablemuch.com/2013/06/multilingual-and-caching-on-nhibernate.html
            //var filterDef = new NHibernate.Engine.FilterDefinition("lf", /*default condition*/ null,
            //                                           new Dictionary<string, NHibernate.Type.IType>
            //                                                           {
            //                                                               { "LanguageCultureCode", NHibernate.NHibernateUtil.String}
            //                                                           }, useManyToOne: false);
            //cfg.AddFilterDefinition(filterDef);



            cfg.Cache(x =>
            {
                // SysCache is not stable on unit testing
                if (!useUnitTest)
                {
                    x.Provider<NHibernate.Caches.SysCache.SysCacheProvider>();

                    // I don't know why SysCacheProvider is not stable on simultaneous unit testing, 
                    // might be SysCacheProvider is just giving one session factory, so simultaneous test see each other caches
                    // This solution doesn't work: http://stackoverflow.com/questions/700043/mstest-executing-all-my-tests-simultaneously-breaks-tests-what-to-do                    
                }
                else
                {
                    // This is more stable in unit testing
                    x.Provider<NHibernate.Cache.HashtableCacheProvider>();
                }


                // http://stackoverflow.com/questions/2365234/how-does-query-caching-improves-performance-in-nhibernate

                // Need to be explicitly turned on so the .Cacheable directive on Linq will work:                    
                x.UseQueryCache = true;
            });



            if (useUnitTest)
                cfg.SetInterceptor(new NHSQLInterceptor());



            //new NHibernate.Tool.hbm2ddl.SchemaUpdate(cfg).Execute(useStdOut: false, doUpdate: true);


            //using (var file = new System.IO.FileStream(@"c:\x\ddl.txt",
            //       System.IO.FileMode.Create,
            //       System.IO.FileAccess.ReadWrite))
            //using (var sw = new System.IO.StreamWriter(file))
            //{
            //    new SchemaUpdate(cfg)
//.........这里部分代码省略.........
开发者ID:MichaelBuen,项目名称:DemoSpaArchitectureMvp,代码行数:101,代码来源:Mapper.cs

示例7: ConfigureNHibernate

        /// <summary>
        /// Configure NHibernate
        /// </summary>
        private void ConfigureNHibernate()
        {
            _configuration = new NHConfiguration();
            _configuration.DataBaseIntegration(x =>
                    {
                        //x.AutoCommentSql = true;
                        //x.Dialect<MsSqlCustomDialect>();
                        x.Dialect<MsSqlCustomDialect>();
                        x.ConnectionString = _connectionString;
                        x.SchemaAction = SchemaAutoAction.Update;
                        x.IsolationLevel = IsolationLevel.ReadCommitted;

                        x.HqlToSqlSubstitutions = "True 1, False 0, true 1, false 0, yes 'Y', no 'N'";
                        x.BatchSize = 15;
                    });

            var mappingAssemblies = _assemblies;
            foreach (var mappingAssembly in mappingAssemblies)
            {
                if (!String.IsNullOrWhiteSpace(mappingAssembly))
                {
                    _configuration.AddAssembly(mappingAssembly);
                }
            }

            _configuration.BuildMappings();
            _configuration.Cache(cfg =>
                                     {
                                         cfg.DefaultExpiration = 120;
                                         cfg.Provider<SysCacheProvider>();
                                         cfg.UseMinimalPuts = true;
                                         cfg.RegionsPrefix = "xyz";
                                         cfg.UseQueryCache = true;
                                     });
            _configuration.SetProperty(NHibernate.Cfg.Environment.CacheDefaultExpiration, 120.ToString());
            _configuration.SetProperty(NHibernate.Cfg.Environment.ShowSql, "false");
            _configuration.Proxy(cfg => cfg.ProxyFactoryFactory<DefaultProxyFactoryFactory>());
            _configuration.SessionFactory()
                          .GenerateStatistics();

            new AuditingEventListener().Register(_configuration);
        }
开发者ID:hoghweed,项目名称:Codebrainr.Site,代码行数:45,代码来源:DataFactory.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");

                Configuration cfg = new Configuration();
				
				
                cfg.Configure(sessionFactoryConfigPath);

                var map = GetMappings(sessionFactoryConfigPath);
                cfg.AddDeserializedMapping(map, "NHSchemaTest");

				//InitializeEventListeners (cfg);
                cfg.Cache(u =>
                {
                    u.UseQueryCache = true;
                    u.RegionsPrefix = "LongTerm";

                }).SessionFactory().Caching.Through<SysCacheProvider>();
                //  Now that we have our Configuration object, create a new SessionFactory
                sessionFactory = cfg.BuildSessionFactory();

                
                if (sessionFactory == null)
                {
                    throw new InvalidOperationException("cfg.BuildSessionFactory() returned null.");
                }

                if (null == configurations)
                    configurations = new Dictionary<string, Configuration>();

                configurations[sessionFactoryConfigPath] = cfg;
                sessionFactories.Add(sessionFactoryConfigPath, sessionFactory);
                //HttpRuntime.Cache.Add(sessionFactoryConfigPath,sessionFactory, null, DateTime.Now.AddDays(7),
                //   TimeSpan.Zero, CacheItemPriority.High, null);

                
            }

            return sessionFactory;
        }
开发者ID:devmicrominds,项目名称:HIS-Project,代码行数:56,代码来源:NHibernateSessionManager.cs

示例9: InitializeNHibernate

        //        public class Order
        //        {
        //            public int Id { get; set; }
        //            public Customer Customer { get; set; }
        //        }
        static void InitializeNHibernate()
        {
            NHibernateProfiler.Initialize();

            cfg = new Configuration();
            cfg.DataBaseIntegration(x =>
                                        {
                                            x.ConnectionStringName = "adventureworks";
                                            x.Driver<SqlClientDriver>();
                                            x.Dialect<MsSql2008Dialect>();
                                            x.IsolationLevel = IsolationLevel.ReadCommitted;
                                            x.Timeout = 10;
                                        });
            cfg.SessionFactoryName("AdventureWorks");
            cfg.Cache(x =>
                          {
                              x.Provider<HashtableCacheProvider>();
                              x.UseQueryCache = true;
                          });
            cfg.SessionFactory().GenerateStatistics();
            cfg.AddAssembly(typeof (Customer).Assembly);
        }
开发者ID:JamesKovacs,项目名称:NHibernateCourseMaterials,代码行数:27,代码来源:Program.cs

示例10: Initialize

        public static Configuration Initialize()
        {
            ModelMapper mapper = new ModelMapper();

            mapper.AddMappings(Assembly.GetAssembly(typeof(NHibernateSessionManager)).GetExportedTypes());

            Configuration cfg = new Configuration();

            cfg.DataBaseIntegration(c =>
            {
                c.Driver<SqlServerCeDriver>();
                c.Dialect<MsSqlCe40Dialect>();

                c.LogSqlInConsole = true;
                c.LogFormattedSql = true;

                c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                c.ConnectionString   = ConnectionString;
            });
            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
            cfg.CurrentSessionContext<ThreadStaticSessionContext>();

            // Set up second level caching
            cfg.Cache(props =>
            {
                props.Provider<AppFabricProvider>();
                props.UseQueryCache = true;
            });

            // (Re-)create the database.
            new SchemaExport(cfg).Execute(false, true, false);

            _sessionFactory = cfg.BuildSessionFactory();

            return cfg;
        }
开发者ID:rageshkrishna,项目名称:NHibernate.Caches.AppFabric,代码行数:36,代码来源:NHibernateSessionManager.cs


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