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


C# ModelMapper.CompileMappingForAllExplicitlyAddedEntities方法代码示例

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


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

示例1: TestGenerators

		public void TestGenerators()
		{
			var mapper = new ModelMapper();

			mapper.Class<A>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Counter)); });
			mapper.Class<B>(e => { e.Id(c => c.Id, c => c.Generator(Generators.UUIDHex)); });
			mapper.Class<C>(e => { e.Id(c => c.Id, c => c.Generator(Generators.UUIDString)); });
			mapper.Class<D>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Increment)); });
			mapper.Class<E>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Select)); });
			mapper.Class<F>(e => { e.Id(c => c.Id, c => c.Generator(Generators.SequenceHiLo)); });
			mapper.Class<G>(e => { e.Id(c => c.Id, c => c.Generator(Generators.SequenceIdentity)); });
			mapper.Class<H>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Table)); });
			mapper.Class<I>(e => { e.Id(c => c.Id, c => c.Generator(Generators.TriggerIdentity)); });

			var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(A).Name)[email protected], Generators.Counter.Class);
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(B).Name)[email protected], Generators.UUIDHex.Class);
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(C).Name)[email protected], Generators.UUIDString.Class);
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(D).Name)[email protected], Generators.Increment.Class);
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(E).Name)[email protected], Generators.Select.Class);
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(F).Name)[email protected], Generators.SequenceHiLo.Class);
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(G).Name)[email protected], Generators.SequenceIdentity.Class);
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(H).Name)[email protected], Generators.Table.Class);
			Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(I).Name)[email protected], Generators.TriggerIdentity.Class);
		}
开发者ID:KaraokeStu,项目名称:nhibernate-core,代码行数:25,代码来源:GeneratorTests.cs

示例2: AddNHibernateSessionFactory

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

示例3: InitNHibernate

        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();
                }
            }
        }
开发者ID:SergeyMironchuk,项目名称:NHibernateStudy,代码行数:35,代码来源:NHibernateHelper.cs

示例4: 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

示例5: ComponentMappingJustOnceDemo

		public void ComponentMappingJustOnceDemo()
		{
			var mapper = new ModelMapper();
			mapper.Component<Name>(comp =>
			{
				comp.Property(name => name.First);
				comp.Property(name => name.Last);
			});
			mapper.Component<Address>(comp =>
			{
				comp.Property(address => address.CivicNumber);
				comp.Property(address => address.Street);
			});
			mapper.Class<Person1>(cm =>
			{
				cm.Id(person => person.Id, map => map.Generator(Generators.HighLow));
				cm.Property(person => person.Test);
				cm.Component(person => person.Name, comp => { });
				cm.Component(person => person.Address, comp => { });
			});

			var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

			var hbmClass = hbmMapping.RootClasses[0];

			var hbmComponents = hbmClass.Properties.OfType<HbmComponent>();
			hbmComponents.Should().Have.Count.EqualTo(2);
			hbmComponents.Select(x => x.Name).Should().Have.SameValuesAs("Name","Address");
		} 
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:29,代码来源:ClassWithComponentsTest.cs

示例6: GetMappings

		protected override HbmMapping GetMappings()
		{
			var mapper = new ModelMapper();
			mapper.Class<Parent>(rc =>
			{
				rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
				rc.Property(x => x.Name);
				rc.List(x => x.Children,
					m =>
					{
						m.Lazy(CollectionLazy.Extra);
						m.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
						m.Inverse(true);
					},
					relation => relation.OneToMany());
			});
			mapper.Class<Child>(rc =>
			{
				rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
				rc.Property(x => x.Name);
				rc.ManyToOne(x => x.Parent);
			});

			return mapper.CompileMappingForAllExplicitlyAddedEntities();
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:25,代码来源:ExtraLazyFixture.cs

示例7: AzureSubcriptionStorage

        /// <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;
        }
开发者ID:remogloor,项目名称:NServiceBus,代码行数:43,代码来源:ConfigureNHibernateAzureSubscriptionStorage.cs

示例8: BuildConfiguration

        public static Configuration BuildConfiguration(string connStr)
        {
            var cfg = new Configuration();

            // See http://fabiomaulo.blogspot.com/2009/07/nhibernate-configuration-through.html
            cfg.DataBaseIntegration(db => {
                db.Driver<SqlClientDriver>();
                db.Dialect<MsSql2012Dialect>();
                db.ConnectionString = connStr; // db.ConnectionStringName = "ConnStr";
                db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";

                // See http://geekswithblogs.net/lszk/archive/2011/07/12/showing-a-sql-generated-by-nhibernate-on-the-vs-build-in.aspx
                //db.LogSqlInConsole = true; // Remove if using Log4Net
                //db.LogFormattedSql = true;
                //db.AutoCommentSql = true;

                db.SchemaAction = SchemaAutoAction.Validate; // This correspond to "hbm2ddl.validate", see http://nhforge.org/blogs/nhibernate/archive/2008/11/23/nhibernate-hbm2ddl.aspx
            });

            var mapper = new ModelMapper();
            mapper.Class<Parent>(map => {
                map.Id(x => x.Id, m => {
                    m.Generator(Generators.GuidComb);
                    m.UnsavedValue(Guid.Empty);
                });
                map.Version(x => x.RowVersion, m => m.UnsavedValue(0));
                map.Property(x => x.Description);
            });
            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
            return cfg;
        }
开发者ID:gimmi,项目名称:randomhacking,代码行数:31,代码来源:NHibernateConfigurator.cs

示例9: 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

示例10: GetMappings

		protected override HbmMapping GetMappings()
		{
			var mapper = new ModelMapper();
			mapper.BeforeMapClass += (inspector, type, map) => map.Id(x=> x.Generator(Generators.GuidComb));
			mapper.Class<Foo>(mc =>
			                  {
													mc.Id(x => x.Id);
													mc.Bag(x => x.Bars, map =>
													                    {
													                    	map.Inverse(true);
													                    	map.Cascade(Mapping.ByCode.Cascade.All);
																								map.Key(km =>
																								        {
																								        	km.Column("FooId");
																													km.OnDelete(OnDeleteAction.Cascade);
																								        });
													                    }, rel => rel.OneToMany());
			                  });
			mapper.Class<Bar>(mc =>
			                  {
													mc.Id(x => x.Id);
			                  	mc.ManyToOne(x=> x.Foo, map=> map.Column("FooId"));
			                  });
			var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
			return mappings;
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:26,代码来源:CachingWithLinq.cs

示例11: 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

示例12: CriarSchema

        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);
        }
开发者ID:TiagoSoczek,项目名称:MOC,代码行数:28,代码来源:SchemaTestCase.cs

示例13: InitializeSessionFactory

 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();
             }
         }
     }
 }
开发者ID:jarrettmeyer,项目名称:portfolio-mvc,代码行数:27,代码来源:NHibernateConfig.cs

示例14: GetMappings

		protected override HbmMapping GetMappings()
		{
			var mapper = new ModelMapper();
			mapper.Class<Author>(rc =>
			{
				rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
				rc.Property(x => x.Name);
				rc.ManyToOne(x => x.Publisher, m => m.Cascade(Mapping.ByCode.Cascade.All));
				rc.Set(x => x.Books, m =>
				{
					m.Cascade(Mapping.ByCode.Cascade.All);
					m.Lazy(CollectionLazy.Lazy);
				}, r => r.OneToMany());
			});
			mapper.Class<Book>(rc =>
			{
				rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
				rc.Property(x => x.Title);
				rc.ManyToOne(x => x.Author);
			});
			mapper.Class<Publisher>(rc =>
			{
				rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
				rc.Property(x => x.Name);
				rc.Set(x => x.Authors, m => m.Cascade(Mapping.ByCode.Cascade.All), r => r.OneToMany());
			});

			return mapper.CompileMappingForAllExplicitlyAddedEntities();
		}
开发者ID:jeynnecool,项目名称:nhibernate-core,代码行数:29,代码来源:TestCollectionInitializingDuringFlush.cs

示例15: GetMappings

		private HbmMapping GetMappings()
		{
			var mapper = new ModelMapper();
			mapper.Class<User>(rt =>
			                   {
			                   	rt.Id(x => x.Id, map => map.Generator(Generators.Guid));
			                   	rt.Property(x => x.Name);
													rt.Set(x => x.Roles, map =>
																							 {
																								 map.Table("UsersToRoles");
																								 map.Inverse(true);
																								 map.Key(km => km.Column("UserId"));
																							 }, rel => rel.ManyToMany(mm =>
																							                          {
																																					mm.Column("RoleId");
																							                          	mm.ForeignKey("FK_RoleInUser");
																							                          }));
			                   });
			mapper.Class<Role>(rt =>
			                   {
			                   	rt.Id(x => x.Id, map => map.Generator(Generators.Guid));
			                   	rt.Property(x => x.Name);
			                   	rt.Set(x => x.Users, map =>
			                   	                     {
			                   	                     	map.Table("UsersToRoles");
																								map.Key(km => km.Column("RoleId"));
																							 }, rel => rel.ManyToMany(mm =>
																							                          {
																																					mm.Column("UserId");
																							                          	mm.ForeignKey("FK_UserInRole");
																							                          }));
			                   });
			var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
			return mappings;
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:35,代码来源:Fixture.cs


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