Ejemplo n.º 1
0
 static Configuration AddLoquaciousMappings(Configuration nhConfiguration)
 {
     var mapper = new NHibernate.Mapping.ByCode.ModelMapper();
     mapper.AddMappings(typeof(OrderSagaDataLoquacious).Assembly.GetTypes());
     nhConfiguration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
     return nhConfiguration;
 }
Ejemplo n.º 2
0
    static Configuration AddLoquaciousMappings(Configuration nhConfiguration)
    {
        var mapper = new NHibernate.Mapping.ByCode.ModelMapper();

        mapper.AddMappings(typeof(OrderSagaDataLoquacious).Assembly.GetTypes());
        nhConfiguration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
        return(nhConfiguration);
    }
        static HbmMapping GetMappings()
        {
            var mapper = new NHibernate.Mapping.ByCode.ModelMapper();

            mapper.AddMappings(Assembly.GetAssembly(typeof(Mappings.CategoryMap)).GetExportedTypes());
            var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            return mapping;
        }
        public static Configuration AddAssemblyByCodeMap(this Configuration config, ModelMapper mapper, Assembly assembly)
        {
            assembly
            .CreateInstances <IModelMap>()
            .Each(x => x.Map(mapper));

            config.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "CodeBy.hbm.xml");

            return(config);
        }
Ejemplo n.º 5
0
        public virtual void Contribute(NHibernate.Mapping.ByCode.ModelMapper mapper)
        {
            var maptypes = GetType().GetNestedTypes().Where(t =>
                                                            t.IsAssignableToGenericType(typeof(ClassMapping <>)) ||
                                                            t.IsAssignableToGenericType(typeof(SubclassMapping <>)) ||
                                                            t.IsAssignableToGenericType(typeof(JoinedSubclassMapping <>)) ||
                                                            t.IsAssignableToGenericType(typeof(UnionSubclassMapping <>))
                                                            ).ToArray();

            if (maptypes.Any())
            {
                mapper.AddMappings(maptypes);
            }
        }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var configuration = new NHibernate.Cfg.Configuration();

            configuration.DataBaseIntegration(c =>
            {
                c.Driver <NHibernate.Driver.NpgsqlDriver>();
                c.Dialect <NHibernate.Dialect.PostgreSQL83Dialect>();

                var connectionString = System.Environment.GetEnvironmentVariable("CONNECTION_STRING");
                Console.WriteLine("Given ConnectionString:" + connectionString);
                c.ConnectionString = connectionString;
                c.LogFormattedSql  = true;
                c.LogSqlInConsole  = true;
            });

            var mapper = new NHibernate.Mapping.ByCode.ModelMapper();

            mapper.AddMapping <PatientMapping>();
            mapper.AddMapping <ObservationMapping>();

            var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            configuration.AddMapping(mapping);

            services.AddSingleton <ICentralConfiguration>(new CentralConfiguration());
            services.AddSingleton <IObservationTransformer>(new ObservationTransformer());

            // add NHibernate services;
            services.AddHibernate(configuration);

            services.AddControllers();

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder
                                  .AllowAnyMethod()
                                  .AllowCredentials()
                                  .SetIsOriginAllowed((host) => true)
                                  .AllowAnyHeader());
            });
        }
Ejemplo n.º 7
0
        // Call this on unit testing, so we can test caching on each test method independently
        public static NHibernate.ISessionFactory BuildSessionFactory(bool useUnitTest = false)
        {
            var mapper = new NHibernate.Mapping.ByCode.ModelMapper();

            mapper.AddMappings
            (
                typeof(Mapper).Assembly.GetTypes()
                .Where(x => x.BaseType.IsGenericType &&
                       x.BaseType.GetGenericTypeDefinition() == typeof(NHibernate.Mapping.ByCode.Conformist.ClassMapping <>))
            );

            // Or you can manually add the mappings
            // mapper.AddMappings(new[]
            //    {
            //        typeof(PersonMapping)
            //    });


            var cfg = new NHibernate.Cfg.Configuration();

            // .DatabaseIntegration! Y U EXTENSION METHOD?
            cfg.DataBaseIntegration(c =>
            {
                var cs = "Server=localhost;Database=test;User Id=sa;password=opensesame93*#;MultipleActiveResultSets=True";

                // SQL Server
                c.Driver <NHibernate.Driver.SqlClientDriver>();
                c.Dialect <NHibernate.Dialect.MsSql2012Dialect>();
                c.ConnectionString = cs;


                c.LogSqlInConsole = true;
                c.LogFormattedSql = true;
            });

            var domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();


            // // AsString is an extension method from NHibernate.Mapping.ByCode:
            // string mappingXml = domainMapping.AsString();

            // // Life without Resharper.
            // string mappingXml = NHibernate.Mapping.ByCode.MappingsExtensions.AsString(domainMapping);

            // System.Console.WriteLine(mappingXml);


            cfg.AddMapping(domainMapping);


            if (useUnitTest)
            {
                cfg.SetInterceptor(new NHSqlInterceptor());
            }

            var sf = cfg.BuildSessionFactory();



            //using (var file = new System.IO.FileStream(@"c:\x\ddl.txt",
            //       System.IO.FileMode.Create,
            //       System.IO.FileAccess.ReadWrite))
            //using (var sw = new System.IO.StreamWriter(file))
            //{
            //    new NHibernate.Tool.hbm2ddl.SchemaUpdate(cfg)
            //        .Execute(scriptAction: sw.Write, doUpdate: false);
            //}

            return(sf);
        }