本文整理汇总了C#中NHibernate.Cfg.Configuration.Configure方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.Configure方法的具体用法?C# Configuration.Configure怎么用?C# Configuration.Configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.Configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppDomainFactory
public static ISessionFactory AppDomainFactory()
{
if (_appDomainFactory == null)
{
lock (_synRoot3)
{
if (_appDomainFactory == null)
{
var createSchema = false;
var configuration = new Configuration()
.DataBaseIntegration(d =>
{
d.ConnectionStringName = Constants.APP_DB;
d.Dialect<MsSql2012Dialect>();
//d.Dialect<Oracle10gDialect>();
d.SchemaAction = SchemaAutoAction.Validate;
})
.Proxy(p => p.ProxyFactoryFactory<DefaultProxyFactoryFactory>())
.CurrentSessionContext<LazySessionContext>()
.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "none")
.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, (createSchema == true) ? SchemaAutoAction.Update.ToString() : SchemaAutoAction.Validate.ToString());
configuration.AddMapping(GetAppMappings());
configuration.BuildMapping();
if (File.Exists(Util.GetFullPath(System.Configuration.ConfigurationManager.AppSettings[Constants.HIBERNATE_CONFIG_KEY])))
configuration.Configure(Util.GetFullPath(System.Configuration.ConfigurationManager.AppSettings[Constants.HIBERNATE_CONFIG_KEY]));
if (File.Exists(Util.GetFullPath(System.Configuration.ConfigurationManager.AppSettings[Constants.HIBERNATE_CONFIG_KEY_App])))
configuration.Configure(Util.GetFullPath(System.Configuration.ConfigurationManager.AppSettings[Constants.HIBERNATE_CONFIG_KEY_App]));
//new NHibernate.Tool.hbm2ddl.SchemaExport(configuration).SetOutputFile(@"c:\temp\MyDDL.sql").Execute(true /*script*/, true /*export to db*/, false /*just drop*/);
_appDomainFactory = configuration.BuildSessionFactory();
}
}
}
return _appDomainFactory;
}
示例2: Load
public override void Load()
{
Bind<IUnitOfWorkFactory>().ToFactory();
Bind<IRepositoryFactory>().ToFactory();
Bind<IUnitOfWork>().To<UnitOfWork>();
Bind<ISessionFactory>().ToMethod(ctx =>
{
var cfg = new Configuration();
#if DEBUG
cfg.Configure();
#else
cfg.Configure(Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, "hibernate-release.cfg.xml"));
#endif
cfg.AddAssembly(Assembly.GetExecutingAssembly());
return cfg.BuildSessionFactory();
});
Bind<IRepository<User>, IUserRepository>().To<UserRepository>();
Bind<IRepository<Artist>>().To<ArtistRepository>();
Bind<IRepository<Album>>().To<AlbumRepository>();
Bind<IRepository<Track>>().To<TrackRepository>();
Bind<IRepository<Playlist>, IPlaylistRepository>().To<PlaylistRepository>();
Bind<IRepository<SocialNetwork>, ISocialNetworkRepository>().To<SocialNetworkRepository>();
Bind<IRepository<UserSocialNetwork>, IUserSocialNetworkRepository>().To<UserSocialNetworkRepository>();
Bind<IRepository<PlaylistTrack>>().To<PlaylistTrackRepository>();
Bind<IRepository<PlaylistListener>>().To<PlaylistListenersRepository>();
Bind<IRepository<SharedPlaylist>>().To<SharedPlaylistRepository>();
Bind<IRepository<PlaylistLike>>().To<PlaylistLikerRepository>();
Bind<IRepository<Notification>, INotificationRepository>().To<NotificationRepository>();
}
示例3: BuildSessionFactory
private void BuildSessionFactory()
{
try
{
var config = new Configuration();
if (string.IsNullOrEmpty(_configurationFile))
{
config.Configure();
}
else
{
config.Configure(_configurationFile);
}
config.AddAssembly(typeof (NhUnitOfWork).Assembly);
_sessionFactory = config.BuildSessionFactory();
}
catch (Exception)
{
_sessionFactory = null;
throw;
}
}
示例4: Configure
/// <summary>
/// Configure according to hibernate.cfg.xml
/// </summary>
/// <param name="config">Configuration to apply the config file to</param>
/// <param name="hibernateFile">Hibernate file path</param>
/// <returns>Updated configuration</returns>
private static Configuration Configure(Configuration config,
string hibernateFile)
{
// In case that hibernate config file location is null find hibernate.cfg.xml
// file in classpath
if (hibernateFile == null)
return config.Configure();
return config.Configure(hibernateFile);
}
示例5: CreateConfiguration
/// <summary>
/// Creates a NHibernate configuration object containing mappings for this model.
/// </summary>
/// <returns>A NHibernate configuration object containing mappings for this model.</returns>
public static Configuration CreateConfiguration()
{
var configuration = new Configuration();
configuration.Configure();
ApplyConfiguration(configuration);
return configuration;
}
示例6: createConfiguration
private Configuration createConfiguration()
{
Configuration cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(Mesto).Assembly);
return cfg;
}
示例7: TestFixtureSetUp
public void TestFixtureSetUp()
{
_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof(Product).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
}
示例8: CargarListas
/// <summary>
/// Carga las listas de la BD que se necesitan para las consultas
/// </summary>
private void CargarListas()
{
//Iniciar sesión
var cfg = new Configuration();
cfg.Configure();
var sessions = cfg.BuildSessionFactory();
var sess = sessions.OpenSession();
//Consulta a la BD
IQuery q1 = sess.CreateQuery("FROM Cliente");
var clientesTodos = q1.List<Cliente>();
//Actualización de la lista global de clientes
clientes = clientesTodos.ToList<Cliente>();
//Consulta a la BD
IQuery q2 = sess.CreateQuery("FROM Empleada");
var empleadosTodos = q2.List<Empleada>();
//Actualización de la lista global de clientes
empleados = empleadosTodos.ToList<Empleada>();
//Carga en las tablas
sess.Close();
}
示例9: GetConfiguration
private static Configuration GetConfiguration()
{
var config = new Configuration();
config.Configure();
config.ConfigureMembershipReboot();
return config;
}
示例10: Init
private static void Init()
{
var config = new Configuration();
config.Configure();
config.AddAssembly(Assembly.GetCallingAssembly());
_sessionFactory = config.BuildSessionFactory();
}
示例11: CriaSessionFactory
private static ISessionFactory CriaSessionFactory()
{
Configuration cfg = new Configuration();
cfg.Configure();
return Fluently.Configure(cfg)
.Mappings(x => x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())).BuildSessionFactory();
}
示例12: GetConfiguration
private static Configuration GetConfiguration()
{
var config = new Configuration();
config.Configure();
config.AddMapping(GetMappings());
return config;
}
示例13: Main
static void Main(string[] args)
{
Console.WriteLine("Started publisher and inserting data.");
Publisher.Start();
var config = new Configuration();
config.Configure("nh.sqlserver.config");
config.SessionFactoryName("Test session factory");
config.AddAssembly(typeof(Dog).Assembly);
new SchemaUpdate(config).Execute(false, true);
using(var sessionFactory = config.BuildSessionFactory())
{
Stopwatch sw = new Stopwatch();
sw.Start();
InsertData(sessionFactory);
Console.WriteLine("Inserting data with logging took: {0}", sw.Elapsed);
sw.Restart();
Publisher.Shutdown();
Console.WriteLine("Publisher shutdown complete in {0}", sw.Elapsed);
Console.WriteLine("inserting data with publisher shutdown");
sw.Restart();
InsertData(sessionFactory);
Console.WriteLine("Inserting data without logging took: {0}", sw.Elapsed);
}
Console.ReadLine();
}
示例14: button3_Click
private void button3_Click(object sender, EventArgs e)
{
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(Domain.User).Assembly);
var sessions = cfg.BuildSessionFactory();
var sess = sessions.OpenSession();
var login = textBox1.Text;
IQuery q = sess.CreateQuery("FROM User u where u.Login=:login").SetParameter("login",login);
var list = q.List<Domain.User>();
if (list.Count > 0 && list[0].Pass == textBox2.Text)
{
var role_id = list[0].Role_id;
IQuery q_role = sess.CreateQuery("FROM Role u where u.Id=:role_id").SetParameter("role_id", role_id);
var list_role = q_role.List<Domain.Role>();
if (list_role[0].Name.Equals("reader"))
{
LibraryForm lib_form = new LibraryForm(list[0]);
lib_form.ShowDialog();
}
else
{
AdminForm admin_form = new AdminForm();
admin_form.ShowDialog();
}
}
else
{
MessageBox.Show("Неверный логин или пароль");
}
}
示例15: NHibernateConfiguration
public static void NHibernateConfiguration(TestContext context)
{
log4net.Config.XmlConfigurator.Configure();
Configuration = new Configuration();
// lendo o arquivo hibernate.cfg.xml
Configuration.Configure();
FilterDefinition filterDef = new FilterDefinition(
"Empresa","EMPRESA = :EMPRESA",
new Dictionary<string, IType>() {{"EMPRESA", NHibernateUtil.Int32}}, false);
Configuration.AddFilterDefinition(filterDef);
filterDef = new FilterDefinition(
"Ativa", "ATIVO = 'Y'",
new Dictionary<string, IType>(), false);
Configuration.AddFilterDefinition(filterDef);
// Mapeamento por código
var mapper = new ModelMapper();
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
Configuration.AddMapping(mapping);
// Gerar o XML a partir do mapeamento de codigo.
//var mappingXMl = mapping.AsString();
// Mapeamento por arquivo, in resource.
Configuration.AddAssembly(Assembly.GetExecutingAssembly());
// Gerando o SessionFactory
SessionFactory = Configuration.BuildSessionFactory();
}