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


C# ModelMapper.CompileMappingForAllExplicitAddedEntities方法代码示例

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


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

示例1: GetMappings

		protected override HbmMapping GetMappings()
		{
			// The impl/mapping of the bidirectional one-to-many sucks but was provided as is
			var mapper = new ModelMapper();
			mapper.BeforeMapClass += (i, t, cm) => cm.Id(map =>
																									 {
																										 map.Column((t.Name + "Id").ToUpperInvariant());
																										 map.Generator(Generators.HighLow, g => g.Params(new { max_lo = "1000" }));
																									 });
			mapper.Class<Customer>(ca =>
			{
				ca.Lazy(false);
				ca.Id(x => x.Id, m => { });
				ca.NaturalId(x => x.Property(c => c.Name, p => p.NotNullable(true)));
				ca.Property(x => x.Address, p => p.Lazy(true));
				ca.Set(c => c.Orders, c =>
				{
					c.Key(x => x.Column("CUSTOMERID"));
					c.Inverse(true);
					c.Cascade(Mapping.ByCode.Cascade.All);
				}, c => c.OneToMany());
			});
			mapper.Class<Order>(cm =>
			                    {
														cm.Id(x => x.Id, m => { });
														cm.Property(x => x.Date);
														cm.ManyToOne(x => x.Customer, map => map.Column("CUSTOMERID"));
			                    });
			return mapper.CompileMappingForAllExplicitAddedEntities();
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:30,代码来源:Fixture.cs

示例2: 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.CompileMappingForAllExplicitAddedEntities();

			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:pontillo,项目名称:PowerNap,代码行数:29,代码来源:ClassWithComponentsTest.cs

示例3: ApplyTo

        public void ApplyTo(Configuration configuration)
        {
            var mapper = new ModelMapper();
            mapper.Class<Node>(node =>
            {
                node.Id(x => x.Id, map =>
                {
                    map.Column("NodeId");
                    map.Generator(Generators.GuidComb);
                });
                node.Property(x => x.Name, map =>
                {
                    map.Length(50);
                    map.Column("NodeName");
                });
                node.Bag(x => x.Connections, bag =>
                {
                    bag.Key(key =>
                    {
                        key.Column("StartNodeId");
                        key.ForeignKey("FK_RelatedNode_Node_StartNodeId");
                    });
                    bag.Table("Connection");
                    bag.Cascade(Cascade.All.Include(Cascade.Remove));
                    bag.Fetch(CollectionFetchMode.Subselect);
                });
            });

            mapper.Component<Connection>(connection =>
            {
                connection.Parent(x => x.Start);
                connection.ManyToOne(x => x.End, manyToOne =>
                {
                    manyToOne.Column("EndNodeId");
                    manyToOne.ForeignKey("FK_RelatedNode_Node_EndNodeId");
                    manyToOne.Cascade(Cascade.Persist);
                    manyToOne.NotNullable(true);
                });
                connection.Component(x => x.Quality, c => {});
            });

            mapper.Component<ConnectionQuality>(connectionQuality =>
            {
                connectionQuality.Property(x => x.UploadMbps);
                connectionQuality.Property(x => x.DownloadMbps);
            });
            configuration.AddMapping(mapper.CompileMappingForAllExplicitAddedEntities());
        }
开发者ID:danmalcolm,项目名称:GraphsInNHibernate,代码行数:48,代码来源:Mapping.cs

示例4: ApplyTo

        public void ApplyTo(Configuration configuration)
        {
            var mapper = new ModelMapper();
            mapper.Class<Thing>(node =>
            {
                node.Id(x => x.Id, map =>
                {
                    map.Column("TestModel1Id");
                    map.Generator(Generators.GuidComb);
                });
                node.Property(x => x.StringProperty, map => map.Length(50));
                node.Property(x => x.BoolProperty);
                node.Property(x => x.DateProperty);
                node.Property(x => x.IntProperty);
                node.Property(x => x.DecimalProperty);
            });

            configuration.AddMapping(mapper.CompileMappingForAllExplicitAddedEntities());
        }
开发者ID:danmalcolm,项目名称:NHQueryRecorder,代码行数:19,代码来源:Mapping.cs

示例5: WhenMapHiloToDifferentSchemaThanClassThenIdHasTheMappedSchema

		public void WhenMapHiloToDifferentSchemaThanClassThenIdHasTheMappedSchema()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(cm =>
			                      {
															cm.Schema("aSchema");
															cm.Id(x => x.Id, idm => idm.Generator(Generators.HighLow, gm => gm.Params(new
															                                                                          {
															                                                                          	table = "hilosequences",
															                                                                          	schema="gSchema"
															                                                                          })));
			                      });
			var conf = new Configuration();
			conf.DataBaseIntegration(x=> x.Dialect<MsSql2008Dialect>());
			conf.AddDeserializedMapping(mapper.CompileMappingForAllExplicitAddedEntities(), "wholeDomain");

			var mappings = conf.CreateMappings(Dialect.Dialect.GetDialect());
			var pc = mappings.GetClass(typeof(MyClass).FullName);
			((SimpleValue)pc.Identifier).IdentifierGeneratorProperties["schema"].Should().Be("gSchema");
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:20,代码来源:Fixture.cs

示例6: GetMappingWithParentInCompo

		private HbmMapping GetMappingWithParentInCompo()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(x =>
			{
				x.Id(c => c.Id);
				x.Component(c => c.Compo);
				x.Bag(c => c.Compos, cm => { });
			});
			mapper.Component<MyCompo>(x =>
			{
				x.Parent(c => c.AManyToOne);
				x.Component(c => c.NestedCompo);
			});
			mapper.Component<MyNestedCompo>(x =>
			{
				x.Component(c => c.Owner);
				x.Property(c => c.Something);
			});
			return mapper.CompileMappingForAllExplicitAddedEntities();
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:21,代码来源:NestedComponetsTests.cs

示例7: WhenDuplicateClassDoesNotDuplicateMapping

		public void WhenDuplicateClassDoesNotDuplicateMapping()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(ca =>
			{
				ca.Id(x => x.Id, map =>
				{
					map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
				});
				ca.Property(x => x.Something);
			});

			mapper.Class<MyClass>(ca =>
			{
				ca.Id(x => x.Id, map =>
				{
					map.Column("MyClassId");
				});
				ca.Property(x => x.Something, map => map.Length(150));
			});
			var hbmMapping = mapper.CompileMappingForAllExplicitAddedEntities();
			ModelIsWellFormed(hbmMapping);
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:23,代码来源:BasicMappingOfSimpleClass.cs

示例8: AddDefaultMapping

        protected virtual void AddDefaultMapping(NHibernate.Cfg.Configuration cfg)
        {
            ModelMapper mm = new ModelMapper();

            mm.Class<ContentItem>(ContentItemCustomization);
            mm.Class<ContentDetail>(ContentDetailCustomization);
            mm.Class<DetailCollection>(DetailCollectionCustomization);
            mm.Class<AuthorizedRole>(AuthorizedRoleCustomization);

            var compiledMapping = mm.CompileMappingForAllExplicitAddedEntities();
            var debugXml = compiledMapping.AsString();
            cfg.AddDeserializedMapping(compiledMapping, "N2");
        }
开发者ID:amarwadi,项目名称:n2cms,代码行数:13,代码来源:ConfigurationBuilder.cs

示例9: WhenMapPropertiesInTheBaseJumpedClassUsingMemberNameThenMapInInherited

		public void WhenMapPropertiesInTheBaseJumpedClassUsingMemberNameThenMapInInherited()
		{
			// ignoring MyClass and using Inherited, as root-class, I will try to map all properties using the base class.
			// NH have to recognize the case and map those properties in the inherited.
			var inspector = new SimpleModelInspector();
			inspector.IsEntity((type, declared) => type == typeof(Inherited));
			inspector.IsRootEntity((type, declared) => type == typeof(Inherited));
			var mapper = new ModelMapper(inspector);
			mapper.Class<MyClass>(mc =>
			                      {
			                      	mc.Id(x => x.Id);
			                      	mc.Property("Simple", map => map.Access(Accessor.Field));
			                      	mc.Property("ComplexType", map => map.Access(Accessor.Field));
			                      	mc.Bag<string>("Bag", y => y.Access(Accessor.Field));
			                      	mc.IdBag<MyCompo>("IdBag", y => y.Access(Accessor.Field));
			                      	mc.List<string>("List", y => y.Access(Accessor.Field));
			                      	mc.Set<string>("Set", y => y.Access(Accessor.Field));
			                      	mc.Map<int, string>("Map", y => y.Access(Accessor.Field));
			                      	mc.OneToOne<Related>("OneToOne", y => y.Access(Accessor.Field));
			                      	mc.ManyToOne<Related>("ManyToOne", y => y.Access(Accessor.Field));
			                      	mc.Any<object>("Any", typeof (int), y => y.Access(Accessor.Field));
			                      	mc.Component("DynamicCompo", new {A = 2}, y => y.Access(Accessor.Field));
			                      	mc.Component<MyCompo>("Compo", y =>
			                      	                               {
			                      	                               	y.Access(Accessor.Field);
			                      	                               	y.Property(c => c.Something);
			                      	                               });
			                      });
			mapper.Class<Inherited>(mc => { });

			HbmMapping mappings = mapper.CompileMappingForAllExplicitAddedEntities();
			HbmClass hbmClass = mappings.RootClasses[0];
			mappings.JoinedSubclasses.Should().Be.Empty();
			hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any",
			                                                                   "DynamicCompo");
			hbmClass.Properties.Select(p => p.Access).All(x => x.Satisfy(access => access.Contains("field.")));
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:37,代码来源:AllPropertiesRegistrationTests.cs

示例10: WhenMapPropertiesInTheInheritedUsingMemberNameThenMapInBase

		public void WhenMapPropertiesInTheInheritedUsingMemberNameThenMapInBase()
		{
			// without ignoring MyClass as root-class I will try to map all properties using the inherited class.
			// NH have to recognize the case and, following Object-Relational-Mapping rules, map those properties in the base class.
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(mc => mc.Id(x => x.Id));
			mapper.JoinedSubclass<Inherited>(mc =>
			                                 {
			                                 	mc.Property("Simple", map => map.Access(Accessor.Field));
			                                 	mc.Property("ComplexType", map => map.Access(Accessor.Field));
			                                 	mc.Bag<string>("Bag", y => y.Access(Accessor.Field));
			                                 	mc.IdBag<MyCompo>("IdBag", y => y.Access(Accessor.Field));
																				mc.List<string>("List", y => y.Access(Accessor.Field));
																				mc.Set<string>("Set", y => y.Access(Accessor.Field));
																				mc.Map<int, string>("Map", y => y.Access(Accessor.Field));
																				mc.OneToOne<Related>("OneToOne", y => y.Access(Accessor.Field));
																				mc.ManyToOne<Related>("ManyToOne", y => y.Access(Accessor.Field));
																				mc.Any<object>("Any", typeof(int), y => y.Access(Accessor.Field));
																				mc.Component("DynamicCompo", new { A = 2 }, y => y.Access(Accessor.Field));
																				mc.Component<MyCompo>("Compo", y =>
			                                 	                           {
			                                 	                           	y.Access(Accessor.Field);
			                                 	                           	y.Property(c => c.Something);
			                                 	                           });
			                                 });
			var mappings = mapper.CompileMappingForAllExplicitAddedEntities();
			var hbmClass = mappings.RootClasses[0];
			var hbmJoinedSubclass = mappings.JoinedSubclasses[0];
			hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo");
			hbmClass.Properties.Select(p => p.Access).All(x => x.Satisfy(access => access.Contains("field.")));
			hbmJoinedSubclass.Properties.Should().Be.Empty();
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:32,代码来源:AllPropertiesRegistrationTests.cs

示例11: WhenMapPropertiesInTheInheritedThenMapInBase

		public void WhenMapPropertiesInTheInheritedThenMapInBase()
		{
			// without ignoring MyClass as root-class I will try to map all properties using the inherited class.
			// NH have to recognize the case and, following Object-Relational-Mapping rules, map those properties in the base class.
			// Where needed, using the SimpleModelInspector, the user can revert this behavior checking the DeclaringType and ReflectedType of the persistent member.
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(mc => mc.Id(x => x.Id));
			mapper.JoinedSubclass<Inherited>(mc =>
														{
															mc.Property(x => x.Simple, map => map.Access(Accessor.Field));
															mc.Property(x => x.ComplexType, map => map.Access(Accessor.Field));
															mc.Bag(x => x.Bag, y => y.Access(Accessor.Field));
															mc.IdBag(x => x.IdBag, y => y.Access(Accessor.Field));
															mc.List(x => x.List, y => y.Access(Accessor.Field));
															mc.Set(x => x.Set, y => y.Access(Accessor.Field));
															mc.Map(x => x.Map, y => y.Access(Accessor.Field));
															mc.OneToOne(x => x.OneToOne, y => y.Access(Accessor.Field));
															mc.ManyToOne(x => x.ManyToOne, y => y.Access(Accessor.Field));
															mc.Any(x => x.Any, typeof(int), y => y.Access(Accessor.Field));
															mc.Component(x => x.DynamicCompo, new { A=2 }, y => y.Access(Accessor.Field));
															mc.Component(x => x.Compo, y =>
																												 {
																													 y.Access(Accessor.Field);
																													 y.Property(c => c.Something);
																												 });
														});
			var mappings = mapper.CompileMappingForAllExplicitAddedEntities();
			var hbmClass = mappings.RootClasses[0];
			var hbmJoinedSubclass = mappings.JoinedSubclasses[0];
			hbmClass.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Simple", "ComplexType", "Bag", "IdBag", "List", "Set", "Map", "Compo", "OneToOne", "ManyToOne", "Any", "DynamicCompo");
			hbmClass.Properties.Select(p => p.Access).All(x=> x.Satisfy(access=> access.Contains("field.")));
			hbmJoinedSubclass.Properties.Should().Be.Empty();
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:33,代码来源:AllPropertiesRegistrationTests.cs


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