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


C# ModelMapper.Component方法代码示例

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


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

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

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

示例3: WhenAClassIsExplicitlyDeclaredAsComponentThenIsComponent

		public void WhenAClassIsExplicitlyDeclaredAsComponentThenIsComponent()
		{
			var autoinspector = new SimpleModelInspector();
			var mapper = new ModelMapper(autoinspector);
			mapper.Component<AEntity>(map => { });

			var inspector = (IModelInspector)autoinspector;
			Assert.That(inspector.IsComponent(typeof(AEntity)), Is.True);
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:9,代码来源:ComponentsTests.cs

示例4: 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.CompileMappingForAllExplicitlyAddedEntities();
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:21,代码来源:NestedComponetsTests.cs

示例5: WhenMapClasByClassThenAutodiscoverParent

		public void WhenMapClasByClassThenAutodiscoverParent()
		{
			var mapper = new ModelMapper();
			mapper.Component<Address>(cm =>
			{
				cm.ManyToOne(x => x.Owner);
				cm.Property(x => x.Street);
				cm.Component(x => x.Number, y => { });
			});
			mapper.Component<Number>(cm =>
			{
				cm.Component(x => x.OwnerAddress, map => { });
				cm.Property(x => x.Block);
			});
			mapper.Class<Person>(cm =>
			{
				cm.Id(x => x.Id);
				cm.Bag(x => x.Addresses, cp => { }, cr => { });
			});
			HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
			VerifyMapping(mapping);
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:22,代码来源:BagOfNestedComponentsWithParentTest.cs

示例6: GetMappings

		protected override HbmMapping GetMappings()
		{
			var mapper = new ModelMapper();

			mapper.Component<Person>(comp =>
			{
				comp.Property(p => p.Name);
				comp.Property(p => p.Dob);
				comp.Unique(true); // hbm2ddl: Generate a unique constraint in the database
			});

			mapper.Class<Employee>(cm =>
			{
				cm.Id(employee => employee.Id, map => map.Generator(Generators.HighLow));
				cm.Property(employee => employee.HireDate);
				cm.Component(person => person.Person);
			});

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

示例7: WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties

		public void WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
			                           {
																	 x.Property(y => y.Code, pm => pm.Length(10));
																	 x.Property(y => y.Name);
			                           });
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>();
			keyProperties.Should().Have.Count.EqualTo(2);
			keyProperties.Select(x => x.Name).Should().Have.SameValuesAs("Code", "Name");
			keyProperties.Where(x => x.Name == "Code").Single().length.Should().Be("10");
		}
开发者ID:RogerKratz,项目名称:nhibernate-core,代码行数:18,代码来源:ComponentAsIdTests.cs

示例8: ModelMapper

		public void WhenMapAttributesOfCustomizedComponentUsedAsComponentAsIdWithCustomizationOverrideThenUseComponentAsIdCustomization()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
			{
				x.Access(Accessor.Field);
				x.Class<MyComponent>();
			});
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, idmap => idmap.Access(Accessor.NoSetter)));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			hbmCompositId.access.Should().Contain("nosetter");
			[email protected]().Contain("MyComponent");
		}
开发者ID:RogerKratz,项目名称:nhibernate-core,代码行数:16,代码来源:ComponentAsIdTests.cs

示例9: WhenMapCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseComponentAsIdCustomization

		public void WhenMapCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseComponentAsIdCustomization()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
			{
				x.Property(y => y.Code, pm=> pm.Length(10));
				x.Property(y => y.Name, pm => pm.Length(20));
			});
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, idmap =>
			{
				idmap.Property(y => y.Code, pm => pm.Length(15));
				idmap.Property(y => y.Name, pm => pm.Length(25));
			}));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>();
			keyProperties.Select(x => x.length).Should().Have.SameValuesAs("15", "25");
		}
开发者ID:RogerKratz,项目名称:nhibernate-core,代码行数:20,代码来源:ComponentAsIdTests.cs

示例10: TestMapComponentEntity

		public void TestMapComponentEntity()
		{
			var cfg = new Configuration().Configure();
			var mapper = new ModelMapper();

			mapper.Class<ClassWithMapComponentEntity>(c =>
			{
				c.Lazy(false);
				c.Id(id => id.Id, id =>
				{
					id.Generator(Generators.Identity);
				});

				c.Map(m => m.Map, col =>
				{
					col.Table("component_entity");
					col.Key(k => k.Column("id"));
				}, key =>
				{
					key.Component(cmp =>
					{
						cmp.Property(p => p.A);
						cmp.Property(p => p.B);
					});
				}, element =>
				{
					element.ManyToMany(e =>
					{
						e.Column("element");
					});
				});
			});

			mapper.Component<Component>(c =>
			{
				c.Property(p => p.A);
				c.Property(p => p.B);
			});

			mapper.Class<Entity>(c =>
			{
				c.Lazy(false);
				c.Id(id => id.A, id =>
				{
					id.Generator(Generators.Identity);
				});
				c.Property(p => p.B);
			});

			cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

			var script = cfg.GenerateSchemaCreationScript(new MsSql2012Dialect());

			Assert.False(script.Any(x => x.Contains("idx")));
		}
开发者ID:liypeng,项目名称:nhibernate-core,代码行数:55,代码来源:MapFixture.cs

示例11: TestMapComponentEntity

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

			mapper.Class<ClassWithMapComponentEntity>(
				c =>
				{
					c.Lazy(false);
					c.Id(id => id.Id, id => id.Generator(Generators.Identity));

					c.Map(
						m => m.Map,
						col =>
						{
							col.Table("component_entity");
							col.Key(k => k.Column("id"));
						},
						key => key.Component(
							cmp =>
							{
								cmp.Property(p => p.A);
								cmp.Property(p => p.B);
							}),
						element => element.ManyToMany(e => e.Column("element")));
				});

			mapper.Component<Component>(
				c =>
				{
					c.Property(p => p.A);
					c.Property(p => p.B);
				});

			mapper.Class<Entity>(
				c =>
				{
					c.Lazy(false);
					c.Id(id => id.A, id => id.Generator(Generators.Identity));
					c.Property(p => p.B);
				});

			var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
			var hbmClass = mappings.RootClasses.FirstOrDefault(c => c.Name == typeof (ClassWithMapComponentEntity).Name);
			var hbmMap = hbmClass.Properties.OfType<HbmMap>().SingleOrDefault();

			Assert.That(hbmMap, Is.Not.Null);
			Assert.That(hbmMap.Item, Is.TypeOf<HbmCompositeMapKey>());
			Assert.That(hbmMap.Item1, Is.TypeOf<HbmManyToMany>());
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:49,代码来源:MapFixture.cs

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

示例13: WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties

		public void WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
									   {
																	 x.Property(y => y.Code, pm => pm.Length(10));
																	 x.Property(y => y.Name);
									   });
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>();
			Assert.That(keyProperties.Count(), Is.EqualTo(2));
			Assert.That(keyProperties.Select(x => x.Name), Is.EquivalentTo(new [] {"Code", "Name"}));
			Assert.That(keyProperties.Single(x => x.Name == "Code").length, Is.EqualTo("10"));
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:18,代码来源:ComponentAsIdTests.cs

示例14: ModelMapper

		public void WhenMapAttributesOfCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseInComponentAsIdCustomization()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
			{
				x.Access(Accessor.Field);
				x.Class<MyComponent>();
			});
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			Assert.That(hbmCompositId.access, Is.StringContaining("field"));
			Assert.That([email protected], Is.StringContaining("MyComponent"));
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:16,代码来源:ComponentAsIdTests.cs


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