static FactoryProvider() { var modelInspector = new MySimpleModelInspector(); Assert.IsNotNull(new Entity()); var mapper = new ModelMapper(modelInspector); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); mapper.BeforeMapClass += (mi, type, map) => map.Id(idmap => idmap.Generator(Generators.HighLow, gmap => gmap.Params(new { table = "NextHighVaues", column = "NextHigh", max_lo = 100, where = String.Format("EntityName = '{0}'", type.Name.ToLowerInvariant()) }))); mapper.BeforeMapClass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant()); mapper.BeforeMapJoinedSubclass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant()); mapper.BeforeMapUnionSubclass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant()); mapper.BeforeMapProperty += (mi, propertyPath, map) => { if (typeof(decimal).Equals(propertyPath.LocalMember.GetPropertyOrFieldType())) { map.Type(NHibernateUtil.Currency); } }; mapper.BeforeMapBag += (mi, propPath, map) => { map.Cascade(Cascade.All.Include(Cascade.DeleteOrphans)); map.BatchSize(10); }; mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); var domainMapping = mapper.CompileMappingForEachExplicitlyAddedEntity(); domainMapping.WriteAllXmlMapping(); var configuration = new Configuration(); configuration.DataBaseIntegration(c => { c.Dialect<MsSql2008Dialect>(); c.ConnectionString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=IntroNH;Integrated Security=True;Pooling=False"; c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote; c.SchemaAction = SchemaAutoAction.Create; }); foreach(var mapping in domainMapping) { configuration.AddMapping(mapping); } configuration.AddAuxiliaryDatabaseObject(CreateHighLowScript(modelInspector, Assembly.GetExecutingAssembly().GetExportedTypes())); Factory=configuration.BuildSessionFactory(); }
static Configuration AddLoquaciousMappings(Configuration nhConfiguration) { ModelMapper mapper = new ModelMapper(); mapper.AddMappings(typeof(OrderSagaDataLoquacious).Assembly.GetTypes()); nhConfiguration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); return nhConfiguration; }
private static HbmMapping GetMappings() { var mapper = new ModelMapper(); mapper.AddMappings(typeof(SessionHelper).Assembly.GetExportedTypes()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mapping; }
private ISessionFactory BuildProjectsSessionFactory() { // register nhibernate var file = "deal.cat"; if (ChiffrageWPF.Properties.Settings.Default.DealsRecentPath != null && ChiffrageWPF.Properties.Settings.Default.DealsRecentPath.Count > 0) { file = ChiffrageWPF.Properties.Settings.Default.DealsRecentPath[ChiffrageWPF.Properties.Settings.Default.DealsRecentPath.Count - 1]; } var dealConfiguration = new Configuration() .Proxy(p => p.ProxyFactoryFactory<NHibernate.Bytecode.DefaultProxyFactoryFactory>()) .DataBaseIntegration(d => { d.ConnectionString = string.Format("Data Source={0};Version=3;", file); d.Dialect<SQLiteDialect>(); d.SchemaAction = SchemaAutoAction.Update; }); var dealMapper = new ModelMapper(); dealMapper.AddMappings(typeof(DealRepository).Assembly.GetTypes()); HbmMapping dealMapping = dealMapper.CompileMappingForAllExplicitlyAddedEntities(); dealConfiguration.AddMapping(dealMapping); return dealConfiguration.BuildSessionFactory(); }
public static void GenerateSchema() { Configuration cfg = new Configuration(); //cfg.SetProperty("nhibernate.envers.default_schema", "audit"); cfg.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg)); var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); cfg.AddMapping(mapping); cfg.AddAssembly(typeof(Model).Assembly); //cfg.IntegrateWithEnvers(); cfg.Configure(); new NHibernate.Tool.hbm2ddl.SchemaExport(cfg) .SetDelimiter(";") //.SetOutputFile("schema.sql") .Execute(false, true, false); }
private static HbmMapping CreateMapping() { var mapper = new ModelMapper(); mapper.AddMappings(GetMappingTypes()); return mapper.CompileMappingForAllExplicitlyAddedEntities(); }
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(); }
public static HbmMapping GetMapping() { var modelMapper = new ModelMapper(); modelMapper.AddMappings(Assembly.GetAssembly(typeof(PeopleMap)).GetExportedTypes()); HbmMapping mapping = modelMapper.CompileMappingForAllExplicitlyAddedEntities(); return mapping; }
private ISessionFactory BuildSessionFactory() { var mapper = new ModelMapper(); var configuration = new Configuration(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); configuration.DataBaseIntegration(c => { c.ConnectionString = _connectionString; c.IsolationLevel = IsolationLevel.ReadCommitted; c.Driver<Sql2008ClientDriver>(); c.Dialect<MsSql2008Dialect>(); c.BatchSize = 50; c.Timeout = 30; #if DEBUG c.LogSqlInConsole = true; c.LogFormattedSql = true; c.AutoCommentSql = true; #endif }); #if DEBUG configuration.SessionFactory().GenerateStatistics(); #endif configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); var sessionFactory = configuration.BuildSessionFactory(); return sessionFactory; }
static SessionFactory() { var connectionString = @"Data Source=.\sqlexpress2014;Initial Catalog=BlogDatabase;Integrated Security=True"; var configuration = new Configuration(); configuration.DataBaseIntegration( x => { x.ConnectionString = connectionString; x.Driver<SqlClientDriver>(); x.Dialect<MsSql2012Dialect>(); }); configuration.SetProperty(Environment.UseQueryCache, "true"); configuration.SetProperty(Environment.UseSecondLevelCache, "true"); configuration.SetProperty(Environment.CacheProvider, typeof(SysCacheProvider).AssemblyQualifiedName); var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); mapper.BeforeMapBag += (modelInspector, member1, propertyCustomizer) => { propertyCustomizer.Inverse(true); propertyCustomizer.Cascade(Cascade.All | Cascade.DeleteOrphans); }; mapper.BeforeMapManyToOne += (modelInspector, member1, propertyCustomizer) => { propertyCustomizer.NotNullable(true); }; mapper.BeforeMapProperty += (inspector, member, customizer) => customizer.NotNullable(true); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); configuration.AddMapping(mapping); sessionFactory = configuration.BuildSessionFactory(); }
public void CreateSqlSchema() { var sqlBuilder = new SqlConnectionStringBuilder(); sqlBuilder.DataSource = "(local)"; sqlBuilder.InitialCatalog = "nservicebus"; sqlBuilder.IntegratedSecurity = true; var cfg = new Configuration() .DataBaseIntegration(x => { x.Dialect<MsSql2008Dialect>(); x.ConnectionString = sqlBuilder.ConnectionString; }); var mapper = new ModelMapper(); mapper.AddMappings(typeof(NHibernate.Config.SubscriptionMap).Assembly.GetExportedTypes()); HbmMapping faultMappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); cfg.AddMapping(faultMappings); File.WriteAllText("schema.sql", ""); new SchemaExport(cfg).Create(x => File.AppendAllText("schema.sql", x), true); subscriptionStorageSessionProvider = new SubscriptionStorageSessionProvider(cfg.BuildSessionFactory()); storage = new SubscriptionStorage(subscriptionStorageSessionProvider); }
private static ModelMapper GetMapper() { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); return mapper; }
private static void InitializeSessionFactory() { if (sessionFactory == null) { lock (mutex) { if (sessionFactory == null) { configuration = new Configuration(); configuration.DataBaseIntegration(db => { db.ConnectionString = connectionString; db.Dialect<MsSql2008Dialect>(); db.Driver<SqlClientDriver>(); db.Timeout = 20; db.LogFormattedSql = Config.LogSql; db.LogSqlInConsole = Config.LogSql; }); var modelMapper = new ModelMapper(); modelMapper.AddMappings(ExportedTypes); var mappingDocument = modelMapper.CompileMappingForAllExplicitlyAddedEntities(); configuration.AddMapping(mappingDocument); sessionFactory = configuration.BuildSessionFactory(); } } } }
private static void InitNHibernate() { lock (LockObject) { if (_sessionFactory == null) { // Создание NHibernate-конфигурации приложения на основании описаний из web.config. // После этого вызова, в том числе, из сборки будут извлечены настройки маппинга, // заданные в xml-файлах. var configure = new Configuration().Configure(); // Настройка маппинга, созданного при помощи mapping-by-code var mapper = new ModelMapper(); mapper.AddMappings(new List<Type> { // Перечень классов, описывающих маппинг typeof (DocumentTypeMap), typeof (DocumentMap), typeof (DocumentWithVersionMap), }); // Добавление маппинга, созданного при помощи mapping-by-code, // в NHibernate-конфигурацию приложения configure.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), null); //configure.LinqToHqlGeneratorsRegistry<CompareValuesGeneratorsRegistry>(); //configure.LinqToHqlGeneratorsRegistry<InGeneratorRegistry>(); configure.DataBaseIntegration(x => { x.LogSqlInConsole = true; x.LogFormattedSql = true; }); _sessionFactory = configure.BuildSessionFactory(); } } }
public void SetUp() { var configuration = new Configuration(); configuration .SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "true") .SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, "create-drop") .SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "true") .SetProperty(NHibernate.Cfg.Environment.CacheProvider, typeof (HashtableCacheProvider).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ReleaseConnections, "on_close") .SetProperty(NHibernate.Cfg.Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName) .SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=:memory:;Version=3;New=True;"); var assembly = Assembly.GetExecutingAssembly(); var modelMapper = new ModelMapper(); modelMapper.AddMappings(assembly.GetTypes()); var hbms = modelMapper.CompileMappingForAllExplicitlyAddedEntities(); configuration.AddDeserializedMapping(hbms, assembly.GetName().Name); ConfigureSearch(configuration); sessionFactory = configuration.BuildSessionFactory(); Session = sessionFactory.OpenSession(); SearchSession = Search.CreateFullTextSession(Session); new SchemaExport(configuration) .Execute(false, true, false, Session.Connection, null); AfterSetup(); }
private static void AddFromConfig(ModelMapper modelMapper, IList<Assembly> assemblies) { for (int i = 0; i < assemblies.Count; ++i) { modelMapper.AddMappings(assemblies[i].GetTypes()); } }
/// <summary> /// Configures the storage with the user supplied persistence configuration /// Azure tables are created if requested by the user /// </summary> /// <param name="config"></param> /// <param name="connectionString"></param> /// <param name="createSchema"></param> /// <returns></returns> public static Configure AzureSubcriptionStorage(this Configure config, string connectionString, bool createSchema, string tableName) { var cfg = new Configuration() .DataBaseIntegration(x => { x.ConnectionString = connectionString; x.ConnectionProvider<TableStorageConnectionProvider>(); x.Dialect<TableStorageDialect>(); x.Driver<TableStorageDriver>(); }); SubscriptionMap.TableName = tableName; var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); var faultMappings = mapper.CompileMappingForAllExplicitlyAddedEntities(); cfg.AddMapping(faultMappings); if (createSchema) { new SchemaExport(cfg).Execute(true, true, false); } var sessionSource = new SubscriptionStorageSessionProvider(cfg.BuildSessionFactory()); config.Configurer.RegisterSingleton<ISubscriptionStorageSessionProvider>(sessionSource); config.Configurer.ConfigureComponent<SubscriptionStorage>(DependencyLifecycle.InstancePerCall); return config; }
public void TestConnection() { var cfg = new Configuration() .DataBaseIntegration(db => { db.ConnectionString = "Server=127.0.0.1;Database=troyanda;Uid=postgres;Pwd=qwerty;"; db.Dialect<PostgreSQL94Dialect>(); db.SchemaAction = SchemaAutoAction.Validate; }); var types = typeof (Cars).Assembly.GetExportedTypes(); /* Add the mapping we defined: */ var mapper = new ModelMapper(); mapper.AddMappings(types); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); cfg.AddMapping(mapping); /* Create a session and execute a query: */ using (ISessionFactory factory = cfg.BuildSessionFactory()) using (ISession session = factory.OpenSession()) using (ITransaction tx = session.BeginTransaction()) { var car = session.Get<Cars>((long)1); var worker = new WorkerServices(cfg, session); var result = worker.GetItemsPresenterForEntity(typeof (Sector)); //session.Save() tx.Commit(); } }
public static void AddNHibernateSessionFactory(this IServiceCollection services) { // By default NHibernate looks for hibernate.cfg.xml // otherwise for Web it will fallback to web.config // we got one under wwwroot/web.config Configuration config = new Configuration(); config.Configure(); // Auto load entity mapping class ModelMapper mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetAssembly(typeof(Employee)).GetExportedTypes()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); config.AddDeserializedMapping(mapping, "NHibernate.Mapping"); SchemaMetadataUpdater.QuoteTableAndColumns(config); // Drop & Recreate database schema new SchemaExport(config).Drop(false, true); new SchemaExport(config).Create(false, true); // Register services services.AddSingleton<ISessionFactory>(provider => config.BuildSessionFactory()); services.AddTransient<ISession>(provider => services.BuildServiceProvider().GetService<ISessionFactory>().OpenSession()); }
public void CriarSchema() { // Apenas no Init da Aplicação var config = new Configuration(); config.DataBaseIntegration(c => { c.Dialect<MsSql2012Dialect>(); c.ConnectionStringName = "ExemploNH"; c.LogFormattedSql = true; c.LogSqlInConsole = true; c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote; }); var modelMapper = new ModelMapper(); modelMapper.AddMappings(typeof (ProdutoMap).Assembly.GetExportedTypes()); config.AddDeserializedMapping(modelMapper.CompileMappingForAllExplicitlyAddedEntities(), "Domain"); ISessionFactory sessionFactory = config.BuildSessionFactory(); // NOTE: Estudar framework FluentMigration var schemaExport = new SchemaExport(config); schemaExport.Create(true, true); }
protected override void PostProcessConfiguration(global::NHibernate.Cfg.Configuration config) { base.PostProcessConfiguration(config); if (FluentNhibernateMappingAssemblies != null) { // add any class mappings in the listed assemblies: var mapper = new ModelMapper(); foreach (var asm in FluentNhibernateMappingAssemblies.Select(Assembly.Load)) { mapper.AddMappings(asm.GetTypes()); } foreach (var mapping in mapper.CompileMappingForEachExplicitlyAddedEntity()) { config.AddMapping(mapping); } foreach (string assemblyName in FluentNhibernateMappingAssemblies) { config.AddMappingsFromAssembly(Assembly.Load(assemblyName)); } } }
private static void ConfigureMappings(Configuration configuration) { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetAssembly(typeof(UserMapping)).GetTypes()); configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public static Configuration AddIdentityMappings(this Configuration cfg) { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); return(cfg); }
private static HbmMapping getDomainMapping() { var mapper = new ModelMapper(); mapper.AddMappings(typeof(NHibernateManager).Assembly.GetExportedTypes()); return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public static void MapAll(Configuration cfg, Assembly a) { var mapper = new ModelMapper(); mapper.AddMappings(a.GetExportedTypes()); var domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); cfg.AddMapping(domainMapping); }
public virtual void BuildModel() { var mapper = new ModelMapper(); var maps = assembly.GetExportedTypes().Where(t => t.IsClass && !t.IsAbstract).ToArray(); mapper.AddMappings(maps); // configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public static HbmMapping GetMappings(Assembly assembly) { ModelMapper mapper = new ModelMapper(); mapper.AddMappings(assembly.GetExportedTypes()); return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
static Configuration AddLoquaciousMappings(Configuration nhConfiguration) { var mapper = new ModelMapper(); mapper.AddMappings(typeof(OrderSagaDataLoquacious).Assembly.GetTypes()); nhConfiguration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); return(nhConfiguration); }
private static HbmMapping CreateMapping() { var mapper = new ModelMapper(); //Add the person mapping to the model mapper mapper.AddMappings(new List<System.Type> { typeof(PersonMap) }); //Create and return a HbmMapping of the model mapping in code return mapper.CompileMappingForAllExplicitlyAddedEntities(); }
protected virtual void ConfigureMappings(ModelMapper modelMapper) { var types = typeof(Order).Assembly.GetExportedTypes() .Where(t => typeof(IConformistHoldersProvider).IsAssignableFrom(t) && !t.IsAbstract) .ToList(); modelMapper.AddMappings(types); }
private static HbmMapping GetMappings() { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetAssembly(typeof(Person)).GetExportedTypes()); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return mapping; }
static SessionFactory() { mapper.AddMappings(typeof(SessionFactory).Assembly.GetTypes()); configuraion.Configure(); configuraion.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public static HbmMapping GetMappings() { var mapper = new ModelMapper(); Type[] exportedTypes = Assembly.GetExecutingAssembly().GetExportedTypes(); mapper.AddMappings(exportedTypes); HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return domainMapping; }
private HbmMapping GetMappings() { ModelMapper mapper = new ModelMapper(); mapper.AddMappings(Assembly.Load("BackendDotNet.Library").GetTypes()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return(mapping); }
private HbmMapping ObterMapemanetoDeClasses() { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetAssembly(GetType()).GetExportedTypes()); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return(mapping); }
private static HbmMapping GetMappings() { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetAssembly(typeof(MyEntityClassMapper)).GetExportedTypes()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return(mapping); }
private static HbmMapping CompileMappings() { var mapper = new ModelMapper(); var aseemblyDominio = System.Reflection.Assembly.Load(System.Configuration.ConfigurationManager.AppSettings["AssemblyMapeamento"]); mapper.AddMappings(aseemblyDominio.GetExportedTypes()); return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public void Configure(Configuration configuration) { var conventions = this.conventionTypes.Select(c => Activator.CreateInstance(c, true)).ToList(); var mapper = new ModelMapper(); mapper.BeforeMapProperty += (inspector, member, customizer) => { foreach (var convention in conventions.OfType <IPropertyConvention>()) { if (convention.Accept(member)) { convention.Apply(customizer); } } }; foreach (var assembly in this.configurationAssemblies) { var types = assembly.GetExportedTypes().Select(c => new { Type = c, Order = GetMappingOrder(c) }).ToList(); var orders = types.Select(c => c.Order).Distinct().OrderBy(c => c); foreach (var order in orders) { var safeOrder = order; mapper.AddMappings(types.Where(c => c.Order == safeOrder).Select(c => c.Type)); } } var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); configuration.AddDeserializedMapping(mapping, this.GetType().Name); foreach (var classMapping in configuration.ClassMappings) { if (classMapping.Version == null) { continue; } var column = classMapping.Version.ColumnIterator.Cast <Column>().First(); var customType = column.Value.Type as CustomType; if (customType != null && customType.UserType is RowVersionType) { // TODO: This is SQL Server specific column.SqlType = "rowversion"; } } configuration.Cache(c => { c.Provider <RtMemoryCacheProvider>(); c.UseQueryCache = true; }); }
private static HbmMapping CreateMapping() { var mapper = new ModelMapper(); var types = Assembly.GetExecutingAssembly().GetExportedTypes().Where(t => t.Namespace == "Ura.Data.Mappings"); mapper.AddMappings(types); return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public void WhenRegisterClassMappingThroughCollectionOfTypeThenMapTheClass() { var mapper = new ModelMapper(); mapper.AddMappings(new [] { typeof(MyClassMap) }); var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); ModelIsWellFormed(hbmMapping); }
private static HbmMapping GetMappings() { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.Load("BusinessLogic").GetTypes()); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return(mapping); }
public static HbmMapping GetMapping() { var modelMapper = new ModelMapper(); modelMapper.AddMappings(Assembly.GetAssembly(typeof(PeopleMap)).GetExportedTypes()); HbmMapping mapping = modelMapper.CompileMappingForAllExplicitlyAddedEntities(); return(mapping); }
private static HbmMapping GetMappings() { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return(mapping); }
private static HbmMapping CompileHbmMappings() { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetAssembly(typeof(MainForm)) .GetExportedTypes()); return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public void WhenRegisterClassMappingThroughCollectionOfTypeThenFilterValidMappings() { var mapper = new ModelMapper(); Assert.That(() => mapper.AddMappings(new[] { typeof(object), typeof(MyClassMap), typeof(MyClass), typeof(MyClassBaseMap <>) }), Throws.Nothing); var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) }); ModelIsWellFormed(hbmMapping); }
public static IServiceCollection AddNHibernate(this IServiceCollection services, string connectionString) { var mapper = new ModelMapper(); mapper.AddMappings(typeof(NHibernateExtensions).Assembly.ExportedTypes); HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); var configuration = new Configuration(); configuration.DataBaseIntegration(config => { config.ConnectionProvider <DriverConnectionProvider>(); config.Dialect <PostgreSQL83Dialect>(); config.Timeout = 60; config.ConnectionString = connectionString; config.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote; config.SchemaAction = SchemaAutoAction.Validate; config.LogFormattedSql = true; config.LogSqlInConsole = true; config.Driver <NpgsqlDriver>(); config.SchemaAction = SchemaAutoAction.Update; //config.SchemaAction = SchemaAutoAction.Recreate; //si hay algun cambio recrea la base de datos, siempre la recrea y inserta }); configuration.AddMapping(domainMapping); var sessionFactory = configuration.BuildSessionFactory(); //string[] resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames(); //Console.WriteLine(resourceNames); //para obtener el nombre del recurso porque le cambie l nombre al proyecto varias veces services.AddSingleton(sessionFactory); services.AddScoped(factory => sessionFactory.OpenSession()); //Servicios vinculados a las entidades services.AddScoped <CarritoDAO>(); services.AddScoped <ColeccionDAO>(); services.AddScoped <ComentarioDAO>(); services.AddScoped <CuponDAO>(); services.AddScoped <DescuentoDAO>(); services.AddScoped <DireccionDAO>(); services.AddScoped <EncargoDAO>(); services.AddScoped <LineaDeItemDAO>(); services.AddScoped <PedidoDAO>(); services.AddScoped <ProductoDAO>(); services.AddScoped <RolDAO>(); services.AddScoped <TipoDeEncargoDAO>(); services.AddScoped <UsuarioDAO>(); services.AddScoped <UsuarioService>(); services.AddScoped <ProductoService>(); return(services); }
public void CompiledMappings_ShouldNotDependOnAddedOrdering_AddedBy_AddMappings() { var mapper = new ModelMapper(); mapper.AddMappings(typeof(EntityMapping).Assembly .GetExportedTypes() //only add our test entities/mappings .Where(t => t.Namespace == typeof(MappingByCodeTest).Namespace)); var config = TestConfigurationHelper.GetDefaultConfiguration(); Assert.DoesNotThrow(() => config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities())); }
private static HbmMapping CreateMapping() { var mapper = new ModelMapper(); mapper.AddMappings(new List <System.Type> { typeof(kpisMap) }); return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
private static HbmMapping CreateMapping() { var mapper = new ModelMapper(); mapper.AddMappings(new List <Type> { typeof(DbSwitcherMap), typeof(DependentTableMap) }); return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public static void AddCodeMappingsFromAssemblies(this Configuration @this, IEnumerable<Assembly> assemblies) { var mapper = new ModelMapper(); foreach (var mappingAssembly in assemblies) { mapper.AddMappings(mappingAssembly.GetTypes()); } @this.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public static HbmMapping GetMappings() { var mapper = new ModelMapper(); Type[] exportedTypes = Assembly.GetExecutingAssembly().GetExportedTypes(); mapper.AddMappings(exportedTypes); HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return(domainMapping); }
private static HbmMapping GetMappings() { var mapper = new ModelMapper(); mapper.AddMappings(NHibernateDatabaseConfiguration.GetMappings()); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); return(mapping); }
private static void CreateExplicitHbmMapping(Configuration configuration, IReadOnlyCollection <Type> mappings, IReadOnlyCollection <Type> assemblyTypes) { if (mappings.Count > 0) { var mapper = new ModelMapper(); mapper.AddMappings(mappings); var hbm = mapper.CompileMappingForAllExplicitlyAddedEntities(); configuration.AddMapping(hbm); } }
private static HbmMapping BuildMappings() { var mappingAssembly = typeof(InMemoryDatabaseCreator).Assembly; var mapper = new ModelMapper(); mapper.AddMappings(mappingAssembly.GetTypes()); return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public static HbmMapping GetMappings(Type[] types) { ModelMapper mapper = new ModelMapper(); foreach (var type in types) { mapper.AddMappings(Assembly.GetAssembly(type).GetExportedTypes()); } return(mapper.CompileMappingForAllExplicitlyAddedEntities()); }
public static ISessionFactory BuildSessionFactory() { var mapper = new ModelMapper(); mapper.BeforeMapBag += MapperOnBeforeMapBag; mapper.BeforeMapManyToOne += MapperOnBeforeMapManyToOne; mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); var config = CreateConfiguration(domainMapping); return config.BuildSessionFactory(); }
private void LoadClassMappings(Configuration configuration) { var mapper = new ModelMapper(); mapper.AddMappings(GetClassMappings()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); configuration.AddMapping(mapping); logger.WriteLine(mapping.AsString()); }
public static Configuration AddAssemblies(this Configuration configuration, IEnumerable <Assembly> assemblies) { foreach (var assembly in assemblies.Where(AssemblyContainsMappingTypes)) { var mapper = new ModelMapper(); mapper.AddMappings(GetConformistMappingTypes(assembly)); configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); } return(configuration); }
private static ISessionFactory CreateSessionFactory() { var mapper = new ModelMapper(); mapper.AddMappings(Assembly.Load("MessageBoard.Domain").GetTypes()); HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); config = new NHibernate.Cfg.Configuration(); config.Configure(); config.AddDeserializedMapping(domainMapping,"domainMapping"); config.Properties[NHibernate.Cfg.Environment.CurrentSessionContextClass]="web"; config.SetProperty(NHibernate.Cfg.Environment.ShowSql, "true").SetProperty(NHibernate.Cfg.Environment.BatchSize, "100"); return config.BuildSessionFactory(); }