本文整理汇总了C#中NHibernate.Cfg.Configuration类的典型用法代码示例。如果您正苦于以下问题:C# NHibernate.Cfg.Configuration类的具体用法?C# NHibernate.Cfg.Configuration怎么用?C# NHibernate.Cfg.Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NHibernate.Cfg.Configuration类属于命名空间,在下文中一共展示了NHibernate.Cfg.Configuration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:spib,项目名称:nhcontrib,代码行数:11,代码来源:TestConfigurationHelper.cs
示例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;
}
开发者ID:cstick,项目名称:MassTransit,代码行数:26,代码来源:TestConfigurator.cs
示例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;
}
}
开发者ID:togakangaroo,项目名称:NServiceBus,代码行数:40,代码来源:SessionFactoryBuilder.cs
示例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);
}
开发者ID:morowind,项目名称:BizCruiser,代码行数:42,代码来源:DbSessionFactory.cs
示例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;
}
开发者ID:ericklombardo,项目名称:Nuaguil.Net,代码行数:32,代码来源:NHibernateSessionManager.cs
示例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);
}
开发者ID:zhangshuiyong,项目名称:TeachingManageSystem,代码行数:7,代码来源:SystemControllerUnitTest.cs
示例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;
}
开发者ID:paradoxfm,项目名称:basemvcsharp,代码行数:7,代码来源:BaseDaoTest.cs
示例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();
}
开发者ID:zorky,项目名称:mymedias,代码行数:33,代码来源:NHIbernateSessionFactory.cs
示例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);
}
开发者ID:zhangshuiyong,项目名称:TeachingManageSystem,代码行数:7,代码来源:StudentControllerUnitTest.cs
示例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;
}
}
开发者ID:kostaswonga,项目名称:NServiceBus,代码行数:38,代码来源:SessionFactoryBuilder.cs
示例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);
}
}
}
开发者ID:hhariri,项目名称:MetaBlogAPI,代码行数:26,代码来源:Program.cs
示例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);
}
开发者ID:ssickles,项目名称:archive,代码行数:7,代码来源:Program.cs
示例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};
}
开发者ID:Kallivayalil,项目名称:KallivayalilNew,代码行数:7,代码来源:ConfigurationFactory.cs
示例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;
}
开发者ID:LeadPipeSoftware,项目名称:LeadPipe.Net.NHibernateExamples,代码行数:32,代码来源:SessionFactoryBuilder.cs
示例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();
}
}
开发者ID:RezaMahmood,项目名称:ChopShop,代码行数:26,代码来源:SessionManager.cs
示例16: GetServerConnection
private ServerConnection GetServerConnection(Configuration configuration)
{
string connectionString = GetConnectionString(configuration);
var conn = new SqlConnection(connectionString);
var server = new Server(new ServerConnection(conn));
return server.ConnectionContext;
}
开发者ID:sthapa123,项目名称:codecampserver,代码行数:7,代码来源:SchemaExportTester.cs
示例17: configTest
public void configTest()
{
var cfg = new NHibernate.Cfg.Configuration().Configure("hibernate.cfg.xml");
using (ISessionFactory sessionFactory = cfg.BuildSessionFactory()) {
}
}
开发者ID:zhangshuiyong,项目名称:TeachingManageSystem,代码行数:7,代码来源:ConfigUnitTest.cs
示例18: InitSessionFactory
public void InitSessionFactory()
{
try
{
string connectionString = "Data Source=Pets.sdf";
string owner = String.Empty;
NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration();
configuration.Properties.Add("dialect", "NHibernate.Dialect.MsSqlCeDialect");
configuration.Properties.Add("connection.driver_class", "NHibernate.Driver.SqlServerCeDriver");
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
configuration.Properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
configuration.Properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
configuration.Properties.Add("connection.connection_string", connectionString);
configuration.Properties.Add("show_sql", "true");
configuration.AddAssembly("DataDriver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
//ToDo :: Add more entity assembly keys if you nHibernate stuff crashes and you don't know why...
_sessionFactory = configuration.BuildSessionFactory();
}
catch (Exception ex)
{
Trace.TraceInformation("Creating the session factory failed with {0}", ex.Message);
}
}
开发者ID:ssdug,项目名称:2013-April-Florey,代码行数:27,代码来源:MySessionFactory.cs
示例19: NhibernateConfigurator
protected NhibernateConfigurator(bool mapDtoAssembly)
{
var assembliesToMap = GetAssembliesToMap(mapDtoAssembly);
var includeBaseTypes = GetIncludeBaseTypes();
var ignoreBaseTypes = GetIgnoreBaseTypes();
var discriminatedTypes = GetDiscriminatedTypes();
var mapDefaultConventions = ShouldMapDefaultConventions();
var assemblyWithAdditionalConventions = GetAssembliesWithAdditionalConventions();
_configuration = new Configuration();
_configuration.Configure();
var autoPersistenceModel = AutoMap.Assemblies(new AutomappingConfiguration(discriminatedTypes.ToArray()), assembliesToMap);
includeBaseTypes.Each(x => autoPersistenceModel.IncludeBase(x));
ignoreBaseTypes.Each(x => autoPersistenceModel.IgnoreBase(x));
assembliesToMap.Each(x => autoPersistenceModel.UseOverridesFromAssembly(x));
if (mapDefaultConventions) autoPersistenceModel.Conventions.AddFromAssemblyOf<PrimaryKeyConvention>();
assemblyWithAdditionalConventions.Each(x => autoPersistenceModel.Conventions.AddAssembly(x));
_sessionFactory = Fluently.Configure(_configuration)
.Mappings(x =>
{
var mappingsContainer = x.AutoMappings.Add(autoPersistenceModel);
var exportNhibernateMappingsFolder = ConfigurationManager.AppSettings["ExportNhibernateMappingsFolder"];
if (!string.IsNullOrWhiteSpace(exportNhibernateMappingsFolder)) mappingsContainer.ExportTo(exportNhibernateMappingsFolder);
})
.BuildSessionFactory();
}
开发者ID:xhafan,项目名称:emailmaker,代码行数:27,代码来源:NhibernateConfigurator.cs
示例20: Main
public static void Main(string[] args)
{
IList<Product> products;
// Don't need to use schema export because of the hbm2dll property.
var cfg = new NHibernate.Cfg.Configuration();
cfg.Configure();
// ensure that mapping hbm.xml file is loaded
cfg.AddAssembly(typeof(MainClass).Assembly);
Product p = new Product() {Name="Captains of Crush Gripper #1", Category="fitness" };
ISessionFactory factory =
cfg.BuildSessionFactory();
using (ISession session = factory.OpenSession())
{
session.Save(p);
session.Flush();
ICriteria sc = session.CreateCriteria<Product>();
products = sc.List<Product>();
Console.WriteLine(products[0].Name);
session.Close();
}
factory.Close();
Console.WriteLine( products.Count );
Console.WriteLine ("Hello World!");
}
开发者ID:I82Much,项目名称:Mono-NHibernate,代码行数:31,代码来源:Main.cs
注:本文中的NHibernate.Cfg.Configuration类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论