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


C# ModelMapper.Subclass方法代码示例

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


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

示例1: WhenSplittedPropertiesThenRegister

		public void WhenSplittedPropertiesThenRegister()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Subclass<Inherited>(map =>
			{
				map.Join("MyClassSplit1", mj =>
				{
					mj.Property(x => x.SomethingA1);
					mj.Property(x => x.SomethingA2);
				});
				map.Join("MyClassSplit2", mj =>
				{
					mj.Property(x => x.SomethingB1);
					mj.Property(x => x.SomethingB2);
				});
				map.Property(x => x.Something0);
			});

			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.Something0)).Should().Be.False();
			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.Something0)).Should().Be.False();

			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.SomethingA1)).Should().Be.True();
			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.SomethingA2)).Should().Be.True();
			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB1)).Should().Be.True();
			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB2)).Should().Be.True();
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:27,代码来源:SubclassPropertiesSplitsTests.cs

示例2: WhenExplicitlyDeclaredAsSubclassThenIsNotTablePerClass

		public void WhenExplicitlyDeclaredAsSubclassThenIsNotTablePerClass()
		{
			var autoinspector = new SimpleModelInspector();
			var mapper = new ModelMapper(autoinspector);
			mapper.Class<MyClass>(x => { });
			mapper.Subclass<Inherited>(x => { });

			var inspector = (IModelInspector)autoinspector;

			inspector.IsTablePerClass(typeof(MyClass)).Should().Be.False();
			inspector.IsTablePerClass(typeof(Inherited)).Should().Be.False();
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:12,代码来源:DefaultClassHierarchyRepresentationTests.cs

示例3: WhenSplittedPropertiesThenRegisterSplitGroupIds

		public void WhenSplittedPropertiesThenRegisterSplitGroupIds()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Subclass<Inherited>(map =>
			{
				map.Join("MyClassSplit1", mj =>
				{
					mj.Property(x => x.SomethingA1);
					mj.Property(x => x.SomethingA2);
				});
				map.Join("MyClassSplit2", mj =>
				{
					mj.Property(x => x.SomethingB1);
					mj.Property(x => x.SomethingB2);
				});
				map.Property(x => x.Something0);
			});

			IEnumerable<string> tablePerClassSplits = inspector.GetPropertiesSplits(typeof(Inherited));
			tablePerClassSplits.Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2");
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:22,代码来源:SubclassPropertiesSplitsTests.cs

示例4: WhenSplittedPropertiesThenRegisterSplitGroupIds

		public void WhenSplittedPropertiesThenRegisterSplitGroupIds()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Subclass<Inherited>(map =>
			{
				map.Join("MyClassSplit1", mj =>
				{
					mj.Property(x => x.SomethingA1);
					mj.Property(x => x.SomethingA2);
				});
				map.Join("MyClassSplit2", mj =>
				{
					mj.Property(x => x.SomethingB1);
					mj.Property(x => x.SomethingB2);
				});
				map.Property(x => x.Something0);
			});

			IEnumerable<string> tablePerClassSplits = inspector.GetPropertiesSplits(typeof(Inherited));
			Assert.That(tablePerClassSplits, Is.EquivalentTo(new [] {"MyClassSplit1", "MyClassSplit2"}));
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:22,代码来源:SubclassPropertiesSplitsTests.cs

示例5: SubclassIsAbstract

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

			var mappings = modelMapper.CompileMappingForAllExplicitlyAddedEntities();

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

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

示例7: WhenMapSplittedPropertiesThenEachPropertyIsInItsSplitGroup

		public void WhenMapSplittedPropertiesThenEachPropertyIsInItsSplitGroup()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Class<MyClass>(map => map.Id(x => x.Id, idmap => { }));
			mapper.Subclass<Inherited>(map =>
			{
				map.Join("MyClassSplit1", mj =>
				{
					mj.Property(x => x.SomethingA1);
					mj.Property(x => x.SomethingA2);
				});
				map.Join("MyClassSplit2", mj =>
				{
					mj.Property(x => x.SomethingB1);
					mj.Property(x => x.SomethingB2);
				});
				map.Property(x => x.Something0);
			});
			var hbmDoc = mapper.CompileMappingFor(new[] { typeof(Inherited) });

			var hbmClass = hbmDoc.SubClasses[0];
			hbmClass.Joins.Select(j => j.table).Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2");
			hbmClass.Properties.Single().Name.Should().Be("Something0");
			var hbmSplit1 = hbmClass.Joins.Single(j => "MyClassSplit1" == j.table);
			hbmSplit1.Properties.Select(p => p.Name).Should().Have.SameValuesAs("SomethingA1", "SomethingA2");
			var hbmSplit2 = hbmClass.Joins.Single(j => "MyClassSplit2" == j.table);
			hbmSplit2.Properties.Select(p => p.Name).Should().Have.SameValuesAs("SomethingB1", "SomethingB2");
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:29,代码来源:SubclassPropertiesSplitsTests.cs


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