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


C# ModelMapper.JoinedSubclass方法代码示例

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


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

示例1: JoinedSubclassIsAbstract

		public void JoinedSubclassIsAbstract()
		{
			//NH-3527
			var modelMapper = new ModelMapper();
			modelMapper.Class<MyClass>(c => { });
			modelMapper.JoinedSubclass<Inherited1>(c =>
			{
				c.Abstract(true);
				c.Extends(typeof(MyClass));
			});

			var mappings = modelMapper.CompileMappingForAllExplicitlyAddedEntities();

			Assert.IsTrue(mappings.JoinedSubclasses[0][email protected]);
			Assert.IsTrue(mappings.JoinedSubclasses[0].extends == typeof(MyClass).FullName);
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:16,代码来源:JoinedSubclassMappingStrategyTests.cs

示例2: GetMapping

		public static HbmMapping GetMapping()
		{
			var mapper = new ModelMapper();

			mapper.Component<Address>(comp =>
			{
				comp.Property(address => address.Street);
				comp.Property(address => address.City);
				comp.Property(address => address.PostalCode);
				comp.Property(address => address.Country);
				comp.ManyToOne(address => address.StateProvince);
			});

			mapper.Class<Animal>(rc => 
			{
				rc.Id(x => x.Id, map => map.Generator(Generators.Native));

				rc.Property(animal => animal.Description);
				rc.Property(animal => animal.BodyWeight);
				rc.ManyToOne(animal => animal.Mother);
				rc.ManyToOne(animal => animal.Father);
				rc.ManyToOne(animal => animal.Zoo);
				rc.Property(animal => animal.SerialNumber);
				rc.Set(animal => animal.Offspring, cm => cm.OrderBy(an => an.Father), rel => rel.OneToMany());
			});

			mapper.JoinedSubclass<Reptile>(jsc => { jsc.Property(reptile => reptile.BodyTemperature); });

			mapper.JoinedSubclass<Lizard>(jsc => { });

			mapper.JoinedSubclass<Mammal>(jsc =>
			{
				jsc.Property(mammal => mammal.Pregnant);
				jsc.Property(mammal => mammal.Birthdate);
			});

			mapper.JoinedSubclass<DomesticAnimal>(jsc =>
			                                      {
			                                      	jsc.ManyToOne(domesticAnimal => domesticAnimal.Owner);
			                                      });

			mapper.JoinedSubclass<Cat>(jsc => { });

			mapper.JoinedSubclass<Dog>(jsc => { });

			mapper.JoinedSubclass<Human>(jsc =>
			{
				jsc.Component(human => human.Name, comp =>
				{
					comp.Property(name => name.First);
					comp.Property(name => name.Initial);
					comp.Property(name => name.Last);
				});
				jsc.Property(human => human.NickName);
				jsc.Property(human => human.Height);
				jsc.Property(human => human.IntValue);
				jsc.Property(human => human.FloatValue);
				jsc.Property(human => human.BigDecimalValue);
				jsc.Property(human => human.BigIntegerValue);
				jsc.Bag(human => human.Friends, cm => { }, rel => rel.ManyToMany());
				jsc.Map(human => human.Family, cm => { }, rel => rel.ManyToMany());
				jsc.Bag(human => human.Pets, cm => { cm.Inverse(true); }, rel => rel.OneToMany());
				jsc.Set(human => human.NickNames, cm =>
				{
					cm.Lazy(CollectionLazy.NoLazy);
					cm.Sort();
				}, cer => { });
				jsc.Map(human => human.Addresses, cm => { }, rel => rel.Component(comp => { }));
			});

			mapper.Class<User>(rc =>
			{
				rc.Id(u => u.Id, im => im.Generator(Generators.Foreign<User>(u => u.Human)));

				rc.Property(user => user.UserName);
				rc.OneToOne(user => user.Human, rm => rm.Constrained(true));
				rc.List(user => user.Permissions, cm => { }, cer => { });
			});

			mapper.Class<Zoo>(rc =>
			{
				rc.Id(x => x.Id, map => map.Generator(Generators.Native));
				rc.Property(zoo => zoo.Name);
				rc.Property(zoo => zoo.Classification);
				rc.Map(zoo => zoo.Mammals, cm => { }, rel => rel.OneToMany());
				rc.Map(zoo => zoo.Animals, cm => { cm.Inverse(true); }, rel => rel.OneToMany());
				rc.Component(zoo => zoo.Address, comp => { });
			});

			mapper.Subclass<PettingZoo>(sc => { });

			mapper.Class<StateProvince>(rc =>
			{
				rc.Id(x => x.Id, map => map.Generator(Generators.Native));
				rc.Property(sp => sp.Name);
				rc.Property(sp => sp.IsoCode);
			});
			return mapper.CompileMappingFor(typeof (Animal).Assembly.GetTypes().Where(t => t.Namespace == typeof (Animal).Namespace));
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:99,代码来源:ShowXmlDemo.cs

示例3: 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.CompileMappingForAllExplicitlyAddedEntities();
			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:Ruhollah,项目名称:nhibernate-core,代码行数:32,代码来源:AllPropertiesRegistrationTests.cs

示例4: MapVideoFeed

        static void MapVideoFeed(ModelMapper mapper)
        {
            mapper.JoinedSubclass<VideoFeed>(
            joinedSubClassMapper =>
            {
                joinedSubClassMapper.Table("cms_VideoFeed");
                joinedSubClassMapper.Key(keyMapper =>
                {
                    keyMapper.Column("Id");
                }
                );

                joinedSubClassMapper.Set(
                    playerGroup => playerGroup.PlaylistAssignments,
                    setPropertiesMapper =>
                    {
                        setPropertiesMapper.Key(
                            keyMapper =>
                            {
                                keyMapper.Column("VideoFeed_Id");
                                //keyMapper.PropertyRef(videoFeed => videoFeed.Id);
                            }
                        );
                        setPropertiesMapper.Cascade(Cascade.All | Cascade.DeleteOrphans);
                        setPropertiesMapper.Inverse(true);
                        //setPropertiesMapper.OrderBy(playlistAssignment => playlistAssignment.AssignmentRank);
                    },
                    collectionElementRelation =>
                    {
                        collectionElementRelation.OneToMany();
                    }
                );
            }
            );
        }
开发者ID:thilaknathen,项目名称:StackOverflow-14133330,代码行数:35,代码来源:Program.cs

示例5: 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.CompileMappingForAllExplicitlyAddedEntities();
			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:Ruhollah,项目名称:nhibernate-core,代码行数:33,代码来源:AllPropertiesRegistrationTests.cs


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