当前位置: 首页>>代码示例>>C#>>正文


C# ModelMapper.AddMappings方法代码示例

本文整理汇总了C#中ModelMapper.AddMappings方法的典型用法代码示例。如果您正苦于以下问题:C# ModelMapper.AddMappings方法的具体用法?C# ModelMapper.AddMappings怎么用?C# ModelMapper.AddMappings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelMapper的用法示例。


在下文中一共展示了ModelMapper.AddMappings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FactoryProvider

        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();
        }
开发者ID:Marceli,项目名称:MVCNHibernate,代码行数:50,代码来源:FactoryProvider.cs

示例2: GenerateSchema

        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);
        }
开发者ID:rungwiroon,项目名称:NHibernate.Spatial,代码行数:25,代码来源:NHibernateHelper.cs

示例3: BuildProjectsSessionFactory

        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();
        }
开发者ID:grozeille,项目名称:chiffrage,代码行数:26,代码来源:NHibernateModule.cs

示例4: CreateMapping

        private static HbmMapping CreateMapping()
        {
            var mapper = new ModelMapper();
            mapper.AddMappings(GetMappingTypes());

            return mapper.CompileMappingForAllExplicitlyAddedEntities();
        }
开发者ID:dddcentral,项目名称:DeveloperDay,代码行数:7,代码来源:NhibernateHelper.cs

示例5: BuildSessionFactory

        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;
        }
开发者ID:prabuw,项目名称:NHibernateTemplate,代码行数:32,代码来源:SessionFactoryFactory.cs

示例6: GetMappings

 private static HbmMapping GetMappings()
 {
     var mapper = new ModelMapper();
     mapper.AddMappings(typeof(SessionHelper).Assembly.GetExportedTypes());
     HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
     return mapping;
 }
开发者ID:gobixm,项目名称:learn,代码行数:7,代码来源:SessionHelper.cs

示例7: 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();
        }
开发者ID:Nerielle,项目名称:Learning,代码行数:30,代码来源:SessionFactory.cs

示例8: CreateSqlSchema

        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);
        }
开发者ID:nghead,项目名称:NServiceBus,代码行数:29,代码来源:SqlServerFixture.cs

示例9: TestConnection

        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();
            }
        }
开发者ID:AndreyRepko,项目名称:Dacha,代码行数:34,代码来源:BasicDataTest.cs

示例10: PostProcessConfiguration

        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));
                }
            }
        }
开发者ID:ora11g,项目名称:NossonCore,代码行数:25,代码来源:FluentNHibernateLocalSessionFactoryObject.cs

示例11: GetMapping

 public static HbmMapping GetMapping()
 {
     var modelMapper = new ModelMapper();
     modelMapper.AddMappings(Assembly.GetAssembly(typeof(PeopleMap)).GetExportedTypes());
     HbmMapping mapping = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
     return mapping;
 }
开发者ID:chenbojian,项目名称:cbjany,代码行数:7,代码来源:NhibernateCfg.cs

示例12: AddLoquaciousMappings

 static Configuration AddLoquaciousMappings(Configuration nhConfiguration)
 {
     ModelMapper mapper = new ModelMapper();
     mapper.AddMappings(typeof(OrderSagaDataLoquacious).Assembly.GetTypes());
     nhConfiguration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
     return nhConfiguration;
 }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:7,代码来源:Program.cs

示例13: GetMapper

        private static ModelMapper GetMapper()
        {
            var mapper = new ModelMapper();
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

            return mapper;
        }
开发者ID:SergerGood,项目名称:OrderSample,代码行数:7,代码来源:SessionFactory.cs

示例14: SetUp

		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();
		}
开发者ID:vcaraulean,项目名称:NHibernate.Search,代码行数:32,代码来源:FluentSearchTestBase.cs

示例15: AddFromConfig

 private static void AddFromConfig(ModelMapper modelMapper, IList<Assembly> assemblies)
 {
    for (int i = 0; i < assemblies.Count; ++i)
    {
       modelMapper.AddMappings(assemblies[i].GetTypes());
    }
 }
开发者ID:michelelepri,项目名称:NHibernate.LoquaciousMappingConfig,代码行数:7,代码来源:ModelMapperExtend.cs


注:本文中的ModelMapper.AddMappings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。