本文整理汇总了C#中NHibernate.Cfg.Configuration类的典型用法代码示例。如果您正苦于以下问题:C# NHibernate.Cfg.Configuration类的具体用法?C# NHibernate.Cfg.Configuration怎么用?C# NHibernate.Cfg.Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NHibernate.Cfg.Configuration类属于命名空间,在下文中一共展示了NHibernate.Cfg.Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDefaultConfiguration
/// <summary>
/// Standar Configuration for tests.
/// </summary>
/// <returns>The configuration using merge between App.Config and hibernate.cfg.xml if present.</returns>
public static NHibernate.Cfg.Configuration GetDefaultConfiguration()
{
NHibernate.Cfg.Configuration result = new NHibernate.Cfg.Configuration();
if (hibernateConfigFile != null)
result.Configure(hibernateConfigFile);
return result;
}
示例2: CreateConfiguration
public static NHibernate.Cfg.Configuration CreateConfiguration([CanBeNull] string connectionString, [CanBeNull] Action<NHibernate.Cfg.Configuration> configurator)
{
Assert.NotNull(typeof(SQLiteConnection));
connectionString = connectionString ?? "Data Source=:memory:";
var cfg = new NHibernate.Cfg.Configuration()
.SetProperty(Environment.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName)
.SetProperty(Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName)
//.SetProperty(Environment.ConnectionDriver, typeof(Sql2008ClientDriver).AssemblyQualifiedName)
//.SetProperty(Environment.Dialect, typeof(MsSql2008Dialect).AssemblyQualifiedName)
.SetProperty(Environment.ConnectionString, connectionString)
//.SetProperty(Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName)
//.SetProperty(Environment.ReleaseConnections, "never")
.SetProperty(Environment.UseSecondLevelCache, "true")
.SetProperty(Environment.UseQueryCache, "true")
.SetProperty(Environment.CacheProvider, typeof (HashtableCacheProvider).AssemblyQualifiedName)
//.SetProperty(Environment.DefaultSchema, "bus")
.AddAssembly(typeof (RegisterUserStateMachine).Assembly)
.AddAssembly(typeof (SagaRepository_Specs).Assembly);
if (configurator != null)
configurator(cfg);
return cfg;
}
示例3: Build
/// <summary>
/// Builds the session factory with the given properties. Database is updated if updateSchema is set
/// </summary>
/// <param name="nhibernateProperties"></param>
/// <param name="updateSchema"></param>
/// <returns></returns>
public ISessionFactory Build(IDictionary<string, string> nhibernateProperties, bool updateSchema)
{
var model = Create.SagaPersistenceModel(typesToScan);
var scannedAssemblies = typesToScan.Select(t => t.Assembly).Distinct();
var nhibernateConfiguration = new Configuration().SetProperties(nhibernateProperties);
foreach (var assembly in scannedAssemblies)
{
nhibernateConfiguration.AddAssembly(assembly);
}
var fluentConfiguration = Fluently.Configure(nhibernateConfiguration)
.Mappings(m => m.AutoMappings.Add(model));
ApplyDefaultsTo(fluentConfiguration);
if (updateSchema)
{
UpdateDatabaseSchemaUsing(fluentConfiguration);
}
try
{
return fluentConfiguration.BuildSessionFactory();
}
catch (FluentConfigurationException e)
{
if (e.InnerException != null)
throw new ConfigurationErrorsException(e.InnerException.Message, e);
throw;
}
}
示例4: CreateStatelessDbSession
/// <summary>
/// 创建StatelessDbSession对象
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="dbDialectProvider">数据库特性对象提供程序</param>
/// <param name="mappingXml">实体关系映射配置Xml文本</param>
/// <returns>返回StatelessDbSession对象</returns>
public virtual StatelessDbSession CreateStatelessDbSession(string connectionString, IDbDialectProvider dbDialectProvider, string mappingXml)
{
ISessionFactory sf = null;
while (!sessionFactories.TryGetValue(connectionString, out sf))
{
IDictionary<string, string> dbSetting = new Dictionary<string, string>
{
["dialect"] = dbDialectProvider.DialectName,
["connection.connection_string"] = connectionString,
};
CustomizeNHSessionFactory(dbSetting);
var x = new NHibernate.Cfg.Configuration();
x = x.AddProperties(dbSetting);
//允许采用配置文件修改NHibernate配置
var hc = ConfigurationManager.GetSection(CfgXmlHelper.CfgSectionName) as NHibernate.Cfg.IHibernateConfiguration;
if ((hc != null && hc.SessionFactory != null) || File.Exists(GetDefaultConfigurationFilePath()))
{
x = x.Configure();
}
if (System.Transactions.Transaction.Current != null)
{
//如果在分布式事务范围内,就将连接释放模式更改为on_close模式,防止auto模式下,重新获取连接,导致分布式事务升级
x.AddProperties(new Dictionary<string, string> {["connection.release_mode"] = "on_close" });
}
//添加实体关系映射
if (!string.IsNullOrWhiteSpace(mappingXml))
{
x.AddXml(mappingXml);
}
sf = x.BuildSessionFactory();
sessionFactories.TryAdd(connectionString, sf);
}
return new StatelessDbSession(sf, connectionString);
}
示例5: 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");
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.Configure(sessionFactoryConfigPath);
// Now that we have our Configuration object, create a new SessionFactory
sessionFactory = cfg.BuildSessionFactory();
if (sessionFactory == null) {
throw new InvalidOperationException("cfg.BuildSessionFactory() returned null.");
}
_sessionFactories.Add(sessionFactoryConfigPath, sessionFactory);
}
return sessionFactory;
}
示例6: Init
public void Init()
{
//SystemController sys = (SystemController)Application["systemController"];
var cfg = new NHibernate.Cfg.Configuration().Configure("hibernate.cfg.xml");
sessionFactory = cfg.BuildSessionFactory();
sys = new SystemController(sessionFactory);
}
示例7: CreateSessionFactory
private static ISessionFactory CreateSessionFactory()
{
Configuration cfg = new Configuration().Configure();
ISessionFactory rez = Fluently.Configure(cfg).Mappings(x => x.FluentMappings.AddFromAssemblyOf<UserMap>()).BuildSessionFactory();
new SchemaExport(cfg).Execute(false, true, false, rez.OpenSession().Connection, null);
return rez;
}
示例8: GetSessionFactory
public static NHibernate.ISessionFactory GetSessionFactory(
string connectionString, List<String> DllNames)
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
// set provider & driver properties
cfg.Properties.Add(
"connection.provider",
"NHibernate.Connection.DriverConnectionProvider");
cfg.Properties.Add(
"connection.driver_class",
"NHibernate.Driver.SQLite20Driver");
cfg.Properties.Add(
"dialect",
"NHibernate.Dialect.SQLiteDialect");
cfg.Properties.Add(
"max_fetch_depth","-1"); // allows for unlimited outer joins (recommeded value is maximum 4
cfg.Properties.Add(
"connection.connection_string",
ConfigurationManager.ConnectionStrings[connectionString].ConnectionString);
cfg.Properties.Add("connection.isolation", "ReadCommitted");
cfg.Properties.Add("query.substitutions", "true 1, false 0");
// here we add all the needed assemblies that contain mappings or objects
foreach (String assemblyName in DllNames)
cfg.AddAssembly(System.Reflection.Assembly.Load(assemblyName));
return cfg.BuildSessionFactory();
}
示例9: Init
public void Init()
{
//StudentController studentController = (StudentController)Session["studentController"];
var cfg = new NHibernate.Cfg.Configuration().Configure("hibernate.cfg.xml");
sessionFactory = cfg.BuildSessionFactory();
studentController = new StudentController(sessionFactory);
}
示例10: Build
/// <summary>
/// Builds the session factory with the given properties. Database is updated if updateSchema is set
/// </summary>
/// <param name="nhibernateProperties"></param>
/// <param name="updateSchema"></param>
/// <returns></returns>
public ISessionFactory Build(IDictionary<string, string> nhibernateProperties, bool updateSchema)
{
var scannedAssemblies = typesToScan.Select(t => t.Assembly).Distinct();
var nhibernateConfiguration = new Configuration().SetProperties(nhibernateProperties);
foreach (var assembly in scannedAssemblies)
nhibernateConfiguration.AddAssembly(assembly);
var mapping = new SagaModelMapper(typesToScan.Except(nhibernateConfiguration.ClassMappings.Select(x => x.MappedClass)));
HackIdIntoMapping(mapping);
nhibernateConfiguration.AddMapping(mapping.Compile());
ApplyDefaultsTo(nhibernateConfiguration);
if (updateSchema)
UpdateDatabaseSchemaUsing(nhibernateConfiguration);
try
{
return nhibernateConfiguration.BuildSessionFactory();
}
catch (Exception e)
{
if (e.InnerException != null)
throw new ConfigurationErrorsException(e.InnerException.Message, e);
throw;
}
}
示例11: Main
static void Main(string[] args)
{
var configuration = new Configuration()
.SetProperty(Environment.ReleaseConnections, "on_close")
.SetProperty(Environment.Dialect, typeof(MsSql2008Dialect).AssemblyQualifiedName)
.SetProperty(Environment.ConnectionDriver, typeof(SqlClientDriver).AssemblyQualifiedName)
.SetProperty(Environment.ConnectionString, ConfigurationManager.ConnectionStrings["db"].ToString())
.SetProperty(Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName);
configuration.AddAssembly(typeof(Blog).Assembly);
SessionManager.Init(configuration, new SingleSessionStorage());
var session = SessionManager.Current;
new SchemaExport(configuration).Execute(false, true, false, session.Connection, null);
if (args.Count() > 0)
{
if (string.Compare(args[0], "/DEMODATA", StringComparison.InvariantCultureIgnoreCase) == 0)
{
DemoData.SetupData(session);
}
}
}
示例12: Main
static void Main(string[] args)
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.Configure();
NHibernate.Tool.hbm2ddl.SchemaExport schema = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);
schema.Create(false, true);
}
示例13: AddListeners
private static void AddListeners(Configuration configuration)
{
Configuration = configuration;
var timeStampListener = new TimeStampListener();
configuration.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[] {timeStampListener};
configuration.EventListeners.PreUpdateEventListeners = new IPreUpdateEventListener[] {timeStampListener};
}
示例14: Build
/// <summary>
/// Builds an NHibernate session factory instance.
/// </summary>
/// <returns>
/// An NHibernate session factory.
/// </returns>
/// <exception cref="Exception">An error occurred while configuring the database connection.</exception>
public ISessionFactory Build()
{
ISessionFactory sessionFactory = null;
try
{
sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString("Server=ZIRCON;Database=NHibernateExample;Trusted_Connection=True;"))
.Mappings(m => { m.FluentMappings.AddFromAssemblyOf<Blog>(); })
.ExposeConfiguration(config =>
{
Configuration = config;
new SchemaExport(config).Execute(true, true, false);
})
.Diagnostics(d => d.Enable()).BuildSessionFactory();
}
catch (Exception ex)
{
throw new Exception("An error occurred while configuring the database connection.", ex);
}
NHibernateProfiler.Initialize();
return sessionFactory;
}
示例15: SessionManager
private SessionManager()
{
if (sessionFactory == null)
{
var configuration = new Configuration()
.AddAssembly(Assembly.GetExecutingAssembly())
.SetProperty("connection.connection_string", GetCoreConnectionString())
.Configure();
//#if (DEBUG)
// {
//var schemadrop = new SchemaExport(configuration);
//schemadrop.Drop(true, false);
//var schemaUpdate = new SchemaUpdate(configuration);
//schemaUpdate.Execute(true, true);
//var schemaCreate = new SchemaExport(configuration);
//schemaCreate.Create(true, true);
// }
//#endif
sessionFactory = configuration.BuildSessionFactory();
}
}