本文整理汇总了C#中NHibernate.Cfg.Configuration.SetInterceptor方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.SetInterceptor方法的具体用法?C# Configuration.SetInterceptor怎么用?C# Configuration.SetInterceptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.SetInterceptor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildSchema
private void BuildSchema(Configuration config)
{
SchemaExport schema = new SchemaExport(config);
schema.Drop(this._criaScript, this._exportaScriptBD);
schema.Create(this._criaScript, this._exportaScriptBD);
config.SetInterceptor(new SqlStatementInterceptor());
}
示例2: GetConfiguration
private Configuration GetConfiguration()
{
var config = new Configuration().Configure();
this.mappingAssemblies.ForEach(ma => config.AddAssembly(ma));
config.SetInterceptor(new SqlQueryInterceptor());
return config;
}
示例3: TemporaryDatabase
/// <summary>
/// Initializes a new instance of the <see cref="TemporaryDatabase"/> class.
/// </summary>
public TemporaryDatabase()
{
_database = new TemporarySqlDatabase();
var configuration = new Configuration();
configuration.SetInterceptor(new PostSaveInterceptor());
configuration.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
configuration.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
configuration.SetProperty("connection.connection_string", _database.ConnectionString);
configuration.SetProperty("dialect", "NHibernate.Dialect.MsSql2005Dialect");
configuration.SetProperty("show_sql", "true");
configuration.AddAssembly(typeof(IRepository).Assembly);
_sessionFactory = configuration.BuildSessionFactory();
var upgradeManager = new DatabaseManager(_database.ConnectionString);
upgradeManager.PerformUpgrade();
}
示例4: TestableDatabase
/// <summary>
/// Initializes a new instance of the <see cref="TestableDatabase"/> class.
/// </summary>
public TestableDatabase()
{
_database = new TemporarySqlDatabase();
var configuration = new Configuration();
configuration.SetInterceptor(new PostSaveInterceptor());
configuration.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
configuration.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
configuration.SetProperty("connection.connection_string", _database.ConnectionString);
configuration.SetProperty("dialect", "NHibernate.Dialect.MsSql2005Dialect");
configuration.SetProperty("show_sql", "true");
configuration.AddMappingsFromAssembly(Cms.Domain.Properties.AssemblyReference.Assembly);
_sessionFactory = configuration.BuildSessionFactory();
var upgradeManager = new ApplicationDatabase(_database.ConnectionString);
upgradeManager.PerformUpgrade();
}
示例5: GetConfiguration
public Configuration GetConfiguration()
{
if (m_Configuration == null)
{
lock (m_Locker)
{
if (m_Configuration == null)
{
m_Configuration = Configuration;
m_Configuration.SetInterceptor(Interceptor);
foreach (IRegisterEventListener registerListener in RegisterEventListeners)
{
registerListener.Register(m_Configuration);
}
}
}
}
return m_Configuration;
}
示例6: BuildConfiguration
public static Configuration BuildConfiguration(string mappingAssembliesFile, string hibernateConfigurationFile, string applicationDirectory, params IInterceptor[] interceptors)
{
var mapper = BuildModelMapper(mappingAssembliesFile, applicationDirectory);
var cfg = new Configuration();
if (File.Exists(hibernateConfigurationFile))
{
cfg.Configure(hibernateConfigurationFile);
}
if (mapper != null)
{
cfg.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), string.Empty);
}
foreach (var interceptor in interceptors)
{
cfg.SetInterceptor(interceptor);
}
return cfg;
}
示例7: Configure
protected override void Configure(Configuration configuration)
{
configuration.SetInterceptor(new ProxyInterceptor());
}
示例8: 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)
//.........这里部分代码省略.........
示例9: SetInterceptors
private static void SetInterceptors(Configuration cfg)
{
cfg.SetInterceptor(new SqlStatementInterceptor());
}
示例10: Configure
protected override void Configure(Configuration configuration)
{
configuration.SetInterceptor(new EntityNameInterceptor());
}
示例11: CreateNHibernateConfiguration
private static Configuration CreateNHibernateConfiguration(IUnityContainer container)
{
var cfg = new Configuration().Configure();
cfg.SetInterceptor(new BuildWithProviderInterceptor(container.Resolve<IServiceProvider>(), cfg.ClassMappings));
return cfg;
}
示例12: CreateSessionFactory
/// <summary>
/// The session factory.
/// </summary>
/// <returns>A session factory.</returns>
protected override ISessionFactory CreateSessionFactory()
{
ISessionFactory factory;
if (!NHibernateEntityContext.sessionFactories.TryGetValue(ENABLED_ENVIRONMENT_MARKER, out factory))
{
IPersistenceConfigurer persistence = null;
switch (ApplicationModelConfiguration.Configuration.Server.Environments.GetEnabledEnvironment().DataSource.Dialect)
{
case "MsSql2005":
{
string connectionString = ApplicationModelConfiguration.Configuration.Server.Environments.GetEnabledEnvironment().DataSource.ConnectionString;
persistence = MsSqlConfiguration.MsSql2005.ConnectionString(connectionString);
}
break;
case "MsSql2008":
{
string connectionString = ApplicationModelConfiguration.Configuration.Server.Environments.GetEnabledEnvironment().DataSource.ConnectionString;
persistence = MsSqlConfiguration.MsSql2008.ConnectionString(connectionString);
}
break;
case "SQLite":
{
string connectionString = ApplicationModelConfiguration.Configuration.Server.Environments.GetEnabledEnvironment().DataSource.ConnectionString;
persistence = SQLiteConfiguration.Standard.ConnectionString(connectionString);
}
break;
default:
throw new NotImplementedException();
}
string mappingAssembly = ApplicationModelConfiguration.Configuration.Server.Environments.GetEnabledEnvironment().Settings[MAPPING_ASSEMBLY_IDENTIFIER].Value;
Configuration configuration = new Configuration();
configuration.SetInterceptor(new NhibernateSqlInterceptor());
FluentConfiguration fluentConfiguration =
Fluently.Configure(configuration)
.Database(persistence)
.Mappings(mappings => mappings.FluentMappings.AddFromAssembly(Assembly.Load(mappingAssembly)));
NHibernateEntityContext.sessionFactories[ENABLED_ENVIRONMENT_MARKER] = factory = fluentConfiguration.BuildSessionFactory();
}
return factory;
}
示例13: CreateConfiguration
private static Configuration CreateConfiguration()
{
var cfg = new Configuration();
//cfg.SetNamingStrategy(new NamingConvention());
cfg.DataBaseIntegration(properties =>
{
//properties.SchemaAction = SchemaAutoAction.Validate;
properties.Dialect<NHibernate.Dialect.MsSql2008Dialect>();
properties.ConnectionStringName = Environment.MachineName;
});
cfg.AddAssembly(Assembly.GetExecutingAssembly());
cfg.SetInterceptor(new DontMakeMeCRY());
cfg.SetProperty(
NHibernate.Cfg.Environment.DefaultBatchFetchSize,
"25");
return cfg;
}