本文整理汇总了C#中NHibernate.Cfg.Configuration.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.AddFile方法的具体用法?C# Configuration.AddFile怎么用?C# Configuration.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.AddFile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: main
public static void main(String[] args)
{
try
{
Configuration cfg = new Configuration();
bool script = true;
// If true then execute db updates, otherwise just generate and display updates
bool doUpdate = true;
//String propFile = null;
for (int i = 0; i < args.Length; i++)
{
if (args[i].StartsWith("--"))
{
if (args[i].Equals("--quiet"))
{
script = false;
}
else if (args[i].StartsWith("--properties="))
{
throw new NotSupportedException("No properties file for .NET, use app.config instead");
//propFile = args[i].Substring( 13 );
}
else if (args[i].StartsWith("--config="))
{
cfg.Configure(args[i].Substring(9));
}
else if (args[i].StartsWith("--text"))
{
doUpdate = false;
}
else if (args[i].StartsWith("--naming="))
{
cfg.SetNamingStrategy(
(INamingStrategy) Activator.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9)))
);
}
}
else
{
cfg.AddFile(args[i]);
}
}
/* NH: No props file for .NET
* if ( propFile != null ) {
Hashtable props = new Hashtable();
props.putAll( cfg.Properties );
props.load( new FileInputStream( propFile ) );
cfg.SetProperties( props );
}*/
new SchemaUpdate(cfg).Execute(script, doUpdate);
}
catch (Exception e)
{
log.Error("Error running schema update", e);
Console.WriteLine(e);
}
}
示例2: OpenSession
public static ISession OpenSession()
{
var configuration = new Configuration();
var configurationPath = HttpContext.Current.Server.MapPath(@"~\Models\hibernate.cfg.xml");
configuration.Configure(configurationPath);
configuration.AddFile(HttpContext.Current.Server.MapPath(@"~\Models\Comment.hbm.xml"));
configuration.AddFile(HttpContext.Current.Server.MapPath(@"~\Models\UserProfile.hbm.xml"));
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
return sessionFactory.OpenSession();
}
示例3: MakeSession
public static ISession MakeSession()
{
var configuration = new Configuration();
configuration.Configure(@"C:\GitRepository\PersonCRUD\PersonCRUD.Domain\Nhibernate\Configuration\hibernate.cfg.xml");
configuration.AddFile(@"C:\GitRepository\PersonCRUD\PersonCRUD.Domain\Nhibernate\Mapping\Person.hbm.xml");
configuration.AddFile(@"C:\GitRepository\PersonCRUD\PersonCRUD.Domain\Nhibernate\Mapping\Phone.hbm.xml");
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
return sessionFactory.OpenSession();
}
示例4: InitalizeSessionFactory
public static void InitalizeSessionFactory(params FileInfo[] hbmFiles)
{
if (SessionFactory != null)
return;
var properties = new Dictionary<string, string>
{
{"connection.driver_class", "NHibernate.Driver.SQLite20Driver"},
{"dialect", "NHibernate.Dialect.SQLiteDialect"},
{"connection.provider", "NHibernate.Connection.DriverConnectionProvider"},
{"connection.connection_string", "Data Source=askme.db;Version=3;New=True;"},
{"connection.release_mode", "on_close"},
{"show_sql", "true"},
{"proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"}
};
Config = new Configuration {Properties = properties};
foreach (FileInfo mappingFile in hbmFiles)
{
Config = Config.AddFile(mappingFile);
}
Config.BuildMapping();
SessionFactory = Config.BuildSessionFactory();
}
示例5: OpenSession
public static ISession OpenSession()
{
var configuration = new Configuration();
var configurationPath = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\hibernate.cfg.xml");
configuration.Configure(configurationPath);
var employeeConfigurationFile = HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\Employee.hbm.xml");
configuration.AddFile(employeeConfigurationFile);
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
return sessionFactory.OpenSession();
}
示例6: AddMappingsFromFilesystem
static void AddMappingsFromFilesystem(Configuration nhConfiguration)
{
var folder = Directory.GetCurrentDirectory();
var hmbFiles = Directory.GetFiles(folder, "*.hbm.xml", SearchOption.TopDirectoryOnly);
foreach (var file in hmbFiles)
{
nhConfiguration.AddFile(file);
}
}
示例7: OpenSession
public static ISession OpenSession()
{
var nHConfig = new Configuration();
var configurationPath= HttpContext.Current.Server.MapPath(@"~\Models\NHibernate\hibernate.cfg.xml");
nHConfig.Configure(configurationPath);
var employeeConfig = HttpContext.Current.Server.MapPath(@"~\Models\NHibernate\EmployeeBranch.hbm.xml");
nHConfig.AddFile(employeeConfig);
ISessionFactory sessionFactory = nHConfig.BuildSessionFactory();
return sessionFactory.OpenSession();
}
示例8: Process
public void Process(string name, Configuration nhConfig)
{
foreach (var file in GetMappingFiles())
{
nhConfig.AddFile(file);
// HBM.XML file must be named to match entity-name.
var entityName = file.Name.Replace(".hbm.xml", string.Empty);
var nhMappingInfo = nhConfig.GetClassMapping(entityName);
var entityDefinition = definitionCreator.CreateFrom(nhMappingInfo);
definitionProvider.Add(entityDefinition);
}
}
示例9: Main
public static void Main(string[] args)
{
try
{
var cfg = new Configuration();
//string propFile = null;
for (int i = 0; i < args.Length; i++)
{
if (args[i].StartsWith("--"))
{
//if (args[i].StartsWith("--properties="))
//{
// propFile = args[i].Substring(13);
//}
//else
if (args[i].StartsWith("--config="))
{
cfg.Configure(args[i].Substring(9));
}
else if (args[i].StartsWith("--naming="))
{
cfg.SetNamingStrategy(
(INamingStrategy)
Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
}
}
else
{
cfg.AddFile(args[i]);
}
}
/* NH: No props file for .NET
if ( propFile != null ) {
Properties props = new Properties();
props.putAll( cfg.getProperties() );
props.load( new FileInputStream( propFile ) );
cfg.setProperties( props );
}
*/
new SchemaValidator(cfg).Validate();
}
catch (Exception e)
{
log.Error("Error running schema update", e);
Console.WriteLine(e);
}
}
示例10: OpenSession
public static ISession OpenSession()
{
var configuration = new Configuration();
var configurationPath =
HttpContext.Current.Server.MapPath(@"~\Models\NHibernate\Configuration\hibernate.cfg.xml");
configuration.Configure(configurationPath);
var usersConfigurationFile =
HttpContext.Current.Server.MapPath(@"~\Models\Nhibernate\Mappings\Users.hbm.xml");
configuration.AddFile(usersConfigurationFile);
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
return sessionFactory.OpenSession();
}
示例11: InitalizeSessionFactory
public static void InitalizeSessionFactory(params FileInfo[] hbmFiles)
{
if (sessionFactory != null)
return;
var properties = new Dictionary<string, string>();
properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
properties.Add("dialect", "NHibernate.Dialect.SQLiteDialect");
properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
properties.Add("connection.connection_string", "Data Source=../../../database/getin.db;Version=3");
properties.Add("connection.release_mode", "on_close");
properties.Add("show_sql", "true");
configuration = new Configuration();
configuration.Properties = properties;
foreach (FileInfo mappingFile in hbmFiles)
{
configuration = configuration.AddFile(mappingFile);
}
configuration.BuildMapping();
sessionFactory = configuration.BuildSessionFactory();
}