internal static FaultManagerSessionFactory CreateSessionFactory(Configuration cfg, bool autoUpdateSchema) { cfg.AddAssembly(typeof(FailureInfo).Assembly); FluentConfiguration fluentConfiguration = Fluently.Configure(cfg).Mappings(m => m.FluentMappings.Add <FailureInfoMap>()); fluentConfiguration.ExposeConfiguration( c => { //default to LinFu if not specifed by user if (!c.Properties.Keys.Contains(Environment.ProxyFactoryFactoryClass)) { c.SetProperty(Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName); } }); if (autoUpdateSchema) { UpdateDatabaseSchemaUsing(fluentConfiguration); } ISessionFactory factory = fluentConfiguration.BuildSessionFactory(); return(new FaultManagerSessionFactory(factory)); }
/// <summary> ///This method will be called after the configuration is processed /// but before the session factory is created. /// Adding the assembly mappings for the /// Fluent NHibernate mapping assemblies to the config object. /// This is done so that later when the session factory is created /// Using the updated configuration it will have /// Fluent NHibernate mappings registered in it. /// </summary> /// <param name=-config-> /// The configuration object that holds the NHibernate configuration. /// </param> protected override void PostProcessConfiguration(Configuration config) { base.PostProcessConfiguration(config); if (FluentNhibernateMappingAssemblies == null) { return; } foreach (string assemblyName in FluentNhibernateMappingAssemblies) { // Loading the assembly by name and // then adding it as the Mapping assembly. config.AddMappingsFromAssembly(Assembly.Load(assemblyName)); } FluentConfiguration fluentConfig = Fluently.Configure(config); fluentConfig.Mappings(AddMappings); //.Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never()) fluentConfig.ExposeConfiguration(cfg => { cfg.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "auto-quote"); }); var factory = fluentConfig.BuildSessionFactory(); }
private static IDictionary <string, ISessionFactory> LoadAllFactories() { var dictionary = new Dictionary <string, ISessionFactory>(2); // Database Dumpstore FluentConfiguration configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012.ConnectionString(cs => cs.FromConnectionStringWithKey("default"))) .Mappings(m => m.FluentMappings .AddFromAssembly(Assembly.Load("Dumpwinkel.Logic")) .Conventions.Add( ForeignKey.EndsWith("Id"), ConventionBuilder.Property .When(criteria => criteria.Expect(x => x.Nullable, Is.Not.Set), x => x.Not.Nullable())) ) .ExposeConfiguration(x => { x.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[] { new EventListener() }; x.EventListeners.PreUpdateEventListeners = new IPreUpdateEventListener[] { new EventListener() }; }); dictionary.Add("default", configuration.BuildSessionFactory()); return(dictionary); }
private static ISessionFactory BuildSessionFactory(string connectionString) { FluentConfiguration configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString)) .Mappings(m => m.FluentMappings .AddFromAssembly(Assembly.GetExecutingAssembly()) .Conventions.Add( ForeignKey.EndsWith("ID"), ConventionBuilder.Property .When(criteria => criteria.Expect(x => x.Nullable, Is.Not.Set), x => x.Not.Nullable())) .Conventions.Add <TableNameConvention>() .Conventions.Add <HiLoConvention>() ) //.ExposeConfiguration(x => //{ // x.EventListeners.PostCommitUpdateEventListeners = // new IPostUpdateEventListener[] { new EventListener() }; // x.EventListeners.PostCommitInsertEventListeners = // new IPostInsertEventListener[] { new EventListener() }; // x.EventListeners.PostCommitDeleteEventListeners = // new IPostDeleteEventListener[] { new EventListener() }; // x.EventListeners.PostCollectionUpdateEventListeners = // new IPostCollectionUpdateEventListener[] { new EventListener() }; //}) ; return(configuration.BuildSessionFactory()); }
public static ISessionFactory GetSessionFactory(SqlConnect sqlConnectProvider) { ISessionFactory factory = null; if (_cacheSessionFactory.TryGetValue(sqlConnectProvider.Name, out factory)) { return(factory); } lock (_lockObj) { if (_cacheSessionFactory.TryGetValue(sqlConnectProvider.Name, out factory)) { return(factory); } FluentConfiguration config = Fluently.Configure(); SetDefaultConfig(config); // if (conn.ProviderName.IndexOf("System.Data.SqlClient", StringComparison.OrdinalIgnoreCase) > -1) BuildMsSqlDatabase(config, sqlConnectProvider.ConnectionString); config.ExposeConfiguration(cfg => { cfg.SetProperty("command_timeout", "120"); var export = new SchemaExport(cfg).SetOutputFile(Path.Combine(PathHelper.AppDataPath, "myDDL.sql")); export.Create(true, false); }); factory = config.BuildSessionFactory(); _cacheSessionFactory[sqlConnectProvider.Name] = factory; } return(factory); }
public void InitializeFactory() { if (!_isInitialized) { FluentConfiguration conf = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(_connection)) .CurrentSessionContext <ThreadLocalSessionContext>() .Mappings(map => { map.FluentMappings.Conventions.Add( new EnumConvention(), new CascadeAllConvention(), new ColumnNameConvention(), new TableNameConvention(), LazyLoad.Never() ); map.FluentMappings.AddFromAssemblyOf <EmployeeMap>(); }) .ExposeConfiguration(x => { x.SetInterceptor(new SqlStatementInterceptor()); x.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[] { new EntityService() }; }); if (!_writeOnly) { conf.ExposeConfiguration(config => new SchemaUpdate(conf.BuildConfiguration()).Execute(true, true)); } _sessionFactory = conf.BuildSessionFactory(); _isInitialized = true; } }
public static ISessionFactory CreateMSSqlNhSessionFactory() { var automappings = AutoMap.AssemblyOf <OrderMapping>(); var constring = configuration.GetConnectionString("DefaultConnectionString"); var dbConfig = MsSqlConfiguration.MsSql2012. ConnectionString(constring); // .Provider("System.Data.SqlClient"); var mappings = Fluently.Configure(). Database(dbConfig.ShowSql()) .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf <Order>(). UseOverridesFromAssemblyOf <OrderMapping>() .Where(d => d.BaseType == typeof(BaseModel) ) )); ISessionFactory buildSessionFactory = null; try{ FluentConfiguration fluentConfiguration = mappings.ExposeConfiguration(d => { new SchemaUpdate(d).Execute(false, true); new SchemaExport(d) .Create(false, false); }); buildSessionFactory = fluentConfiguration.BuildSessionFactory(); } catch (Exception ex) { Console.Write("exeption is ", ex.StackTrace); } return(buildSessionFactory); }
/// <summary> /// The register unit of work. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="container"> /// The container. /// </param> /// <param name="serviceProvider"> /// The service provider. /// </param> /// <exception cref="Exception"> /// </exception> public void RegisterUnitOfWork( IDataConfiguration configuration, IContainer container, IServiceProvider serviceProvider = null) { if (configuration == null || configuration.ConnectionStrings == null || !configuration.ConnectionStrings.ContainsKey("RepoTestNHibSqlServer")) { throw new Exception("Invalid configuration specified in database manager"); } var nHibConfig = MsSqlConfiguration.MsSql2012.ConnectionString(configuration.ConnectionStrings["RepoTestNHibSqlServer"]); Configuration = Fluently.Configure().Database(nHibConfig) .Mappings(o => o.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly())); Factory = Configuration.BuildSessionFactory(); container.Configure( config => { config.For <IUnitOfWork>().LifecycleIs(Lifecycles.Transient).Use <SqlServerFullContext>() .Ctor <ISessionFactory>("factory").Is(Factory); }); // End }
public BaseRepository() { string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["kunenaForum"].ConnectionString; AutomappingConfiguration autoConfig = new AutomappingConfiguration(); TableNameConvention tableNameConvention = new TableNameConvention(); FluentConfiguration config = FluentNHibernate.Cfg.Fluently.Configure().Database( MySQLConfiguration.Standard .ConnectionString(connectionString) ).Mappings(m => { m.FluentMappings.Add <CategoryClassMap>(); //( //.AddFromAssembly(classMapAssembly); m.FluentMappings.Add <ContentClassMap>(); m.FluentMappings.Add <AttachmentClassMap>(); m.FluentMappings.Add <UserClassMap>(); m.FluentMappings.Add <UserProfileClassMap>(); m.FluentMappings.Add <SearchClassMap>(); m.FluentMappings.Add <MessageClassMap>(); m.FluentMappings.Add <MessageTextClassMap>(); //m.AutoMappings.Add( // //AutoMap.AssemblyOf<BaseRepository>(autoConfig).Conventions.Add<TableNameConvention>(tableNameConvention) // AutoMap.Assembly(Assembly.GetExecutingAssembly(), autoConfig).Conventions.Add<TableNameConvention>(tableNameConvention) //); } ); sessionFactory = config.BuildSessionFactory(); session = sessionFactory.OpenSession(); }
private static ISessionFactory CreateSessionFactoryFor( string[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, Configuration cfg, IPersistenceConfigurer persistenceConfigurer) { FluentConfiguration fluentConfiguration = Fluently.Configure(cfg); if (persistenceConfigurer != null) { fluentConfiguration.Database(persistenceConfigurer); } fluentConfiguration.Mappings(m => { foreach (var mappingAssembly in mappingAssemblies) { var assembly = Assembly.LoadFrom(MakeLoadReadyAssemblyName(mappingAssembly)); m.HbmMappings.AddFromAssembly(assembly); m.FluentMappings.AddFromAssembly(assembly) .Conventions.AddAssembly(assembly); } if (autoPersistenceModel != null) { m.AutoMappings.Add(autoPersistenceModel); } }); return(fluentConfiguration.BuildSessionFactory()); }
public void InitSessionFactory() { string connectionString = ConfigurationManager.ConnectionStrings[GlobalVars.ConnectionString].ConnectionString; FluentConfiguration fc = Fluently.Configure() .Database(OracleDataClientConfiguration.Oracle10.ConnectionString(c => c.Is(connectionString)) .ShowSql() // .Driver<NHibernate.Driver.OracleDataClientDriver>() .Driver <NHibernate.Driver.OracleManagedDataClientDriver>() // .ConnectionString(connectionString) .ShowSql()); //.Mappings(m => m.HbmMappings.AddFromAssemblyOf<BeneficiarioMap>()); /*.Mappings(m => m.FluentMappings * .AddFromAssemblyOf<PersonMap>()) * * .Mappings(m => m.FluentMappings * .AddFromAssemblyOf<Person>() * .Conventions.Setup(c => * { * c.Add<ColumnNameConvention>(); * c.Add<ReferenceConvention>(); * c.Add<PrimaryKeyNameConvention>(); * }));*/ _sessionFactory = fc.BuildSessionFactory(); }
private static ISessionFactory CriarSessao() { if (session != null) { return(session); } FluentConfiguration _configuration = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString( x => x.Server("localhost") .Username("root") .Password("") .Database("dbusuario") ) ) .Mappings( x => x.FluentMappings.AddFromAssemblyOf <UsuarioMap>()); //.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)); //comentar a linha acima apos a primeira execucao sob o risco de sobrescrever os dados ja populados no DB session = _configuration.BuildSessionFactory(); return(session); }
private static ISession CreateSession(this FluentConfiguration configuration) { var session = configuration.BuildSessionFactory().OpenSession(); new SchemaExport(savedConfiguration ?? configuration.BuildConfiguration()) .Execute(true, true, false, session.Connection, Console.Out); return(session); }
/// <summary> /// Creates the session factory. /// </summary> /// <returns> /// The session factory. /// </returns> public ISessionFactory CreateSessionFactory() { FluentConfiguration configuration = Fluently.Configure(this.GetConfiguration()); AddMappings(configuration); return(configuration.BuildSessionFactory()); }
public static ISessionFactory BuildSessionFactory(string connectionString) { FluentConfiguration configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString)) .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())); return(configuration.BuildSessionFactory()); }
public static ISessionFactory CreateSessionFactory() { FluentConfiguration configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012.ConnectionString( x => x.FromConnectionStringWithKey("Conexao")).ShowSql()) .Mappings(x => x.FluentMappings.AddFromAssemblyOf <Categoria>()); return(configuration.BuildSessionFactory()); }
public static void CriarTabelasBanco() { FluentConfiguration configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012.ConnectionString(x => x.FromConnectionStringWithKey("Conexao")).ShowSql()) .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)) .Mappings(x => x.FluentMappings.AddFromAssemblyOf <Categoria>()); configuration.BuildSessionFactory(); }
public static CoreNHibernate.ISessionFactory CreateSessionFactory(DBTypes dbType) { FluentConfiguration config = Fluently.Configure(); switch (dbType) { case DBTypes.Oracle: config = OracleHelper.ConfigurationFactory(); break; case DBTypes.MSSQL: config = MsSqlHelper.ConfigurationFactory(); break; case DBTypes.SQLite: config = SQLiteHelper.ConfigurationFactory(); break; case DBTypes.MySQL: default: throw new NotImplementedException("Not implemented yet..."); } var enversConf = new EnversNHibernate.Configuration.Fluent.FluentConfiguration(); List <Type> domainEntities = Assembly.GetAssembly(typeof(Clients)).GetTypes() // Assembly.Load("bilisimHR.DataLayer.Core").GetTypes() .Where(t => (typeof(Entity <int>).IsAssignableFrom(t) && !t.IsGenericType)) .ToList(); foreach (Type type in domainEntities) { enversConf.Audit(type); } CoreNHibernate.Cfg.Configuration cfg = new CoreNHibernate.Cfg.Configuration(); cfg = config.BuildConfiguration(); cfg.BuildMappings(); cfg.SetInterceptor(new TrackingInterceptor()); //Envers RevType Values //0(ADD), 1(MODIFY) and 2(DELETE) ConfigurationKey.AuditTableSuffix.SetUserValue(cfg, "_LOG"); IRevisionInfoService revInfoService = new RevisionInfoService(); // Service Locator Registry ServiceLocator.RegisterService(revInfoService); ServiceLocator.RegisterService(new HttpRequestMessageService()); enversConf.SetRevisionEntity <CustomRevInfo>(e => e.Id, e => e.RevisionDate, new CustomRevInfoListener()); cfg.IntegrateWithEnvers(enversConf); config.ExposeConfiguration(exp => new SchemaUpdate(cfg).Execute(false, true)) .ExposeConfiguration(c => { c.CurrentSessionContext <CoreNHibernate.Context.CallSessionContext>(); }); //config.ExposeConfiguration(exp => new SchemaExport(cfg).Execute(true, true, false)); return(config.BuildSessionFactory()); }
public ISessionFactory BuildSessionFactory() { foreach (var interceptor in interceptors) { configuration.ExposeConfiguration(x => x.SetInterceptor(interceptor)); } return(configuration.BuildSessionFactory()); }
public static ISessionFactory BuildSessionFactory(string connectionString) { FluentConfiguration configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString)) .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())) .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)); return(configuration.BuildSessionFactory()); }
/// <summary> /// Cria uma nova sessão caso ainda não exista uma criada /// </summary> /// <returns></returns> private static ISessionFactory CreateSession() { if (session != null) { return(session); } session = _configuration.BuildSessionFactory(); return(session); }
public static void ReBuildDB() { var factory = reBiuldConfiguration.BuildSessionFactory(); Run("Drop database HSEvents;", factory); Run("Create database HSEvents;", factory); factory.Close(); UpdateDB(SessionFactory); }
public NHibernateUnitOfWorkFactory(string connectionString) { _connectionString = connectionString; _configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectionString).ShowSql().AdoNetBatchSize(500)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf <TMappingAssembly>()); _sessionFactory = _configuration.BuildSessionFactory(); }
public ISessionFactory InitSessionFactory() { _fluentConfiguration = Fluently.Configure() .Mappings(m => m.FluentMappings.AddFromAssemblyOf <PizzaMap>()) .Database(MsSqlConfiguration.MsSql2008.ShowSql() .IsolationLevel("ReadCommitted") .ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString")) .ShowSql()); return(_fluentConfiguration.BuildSessionFactory()); }
public void CriarScriptsBanco() { string conectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Bibliotech;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; FluentConfiguration configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(conectionString)) .ExposeConfiguration(cfg => new SchemaExport(cfg).SetOutputFile("ScriptBanco.sql").Create(true, false)) .Mappings(x => x.FluentMappings.AddFromAssemblyOf <Pessoa>()); configuration.BuildSessionFactory(); }
public static void Configurar() { FluentConfiguration configuracao = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012 .ConnectionString(StringConexao) .ShowSql()) .Mappings(c => c.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())) .ExposeConfiguration(c => new SchemaUpdate(c).Execute(true, true)); _sessionFactory = configuracao.BuildSessionFactory(); }
public static ISessionFactory BuildSessionFactory(FluentConfiguration config) { try { return(config.BuildSessionFactory()); } catch (ArgumentException x) { log.FatalException("Error while building session factory", x); throw; } catch (FluentConfigurationException x) { log.FatalException("Error while building session factory", x); throw; } }
public SessionFactory() { try { FluentConfiguration config = obterConfiguracaoFluent(); this.ISessionFactory = config.BuildSessionFactory(); } catch (Exception ex) { throw; } }
private static ISessionFactory BuildSessionFactory() { IPersistenceConfigurer dbConfiguration = SQLiteConfiguration .Standard.UsingFile("order.db"); FluentConfiguration fluentConfiguration = Fluently.Configure() .Database(dbConfiguration) .Mappings(m => m.FluentMappings.AddFromAssemblyOf <HealthController>()) .CurrentSessionContext <ThreadStaticSessionContext>(); return(fluentConfiguration.BuildSessionFactory()); }
private void Init() { _configuration = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(x => x .Server("localhost") .Username("root") .Password("senha") .Database("apphibernate"))) .Mappings(c => c.FluentMappings.AddFromAssemblyOf <WAppFluentNhibernate.Db.Poco.Cliente>()); _sessiofactory = _configuration.BuildSessionFactory(); _session = _sessiofactory.OpenSession(); }