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


C# ModelMapper.CompileMappingFor方法代码示例

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


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

示例1: WhenMapDynCompoAttributesThenMapAttributes

		public void WhenMapDynCompoAttributesThenMapAttributes()
		{
			var mapper = new ModelMapper();
			mapper.Class<Person>(map =>
			{
				map.Id(x => x.Id, idmap => { });
				map.Component(x => x.Info, new { MyInt = 5}, z =>
				                                             {
																											 z.Access(Accessor.Field);
																											 z.Insert(false);
																											 z.Update(false);
																											 z.Unique(true);
																											 z.OptimisticLock(false);
				                                             });
			});

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Person) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmDynamicComponent = hbmClass.Properties.OfType<HbmDynamicComponent>().SingleOrDefault();
			hbmDynamicComponent.access.Should().Contain("field");
			hbmDynamicComponent.insert.Should().Be.False();
			hbmDynamicComponent.update.Should().Be.False();
			hbmDynamicComponent.optimisticlock.Should().Be.False();
			hbmDynamicComponent.unique.Should().Be.True();
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:25,代码来源:DynamicComponentMappingTests.cs

示例2: MapClassWithIdAndProperty

		public void MapClassWithIdAndProperty()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(ca =>
			{
				ca.Id("id", map =>
				{
					map.Column("MyClassId");
					map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
				});
				ca.Version("version", map => { });
				ca.Property("something", map => map.Length(150));
			});
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			hbmClass.Should().Not.Be.Null();
			var hbmId = hbmClass.Id;
			hbmId.Should().Not.Be.Null();
			hbmId.name.Should().Be("id");
			hbmId.access.Should().Be("field");
			var hbmGenerator = hbmId.generator;
			hbmGenerator.Should().Not.Be.Null();
			[email protected]().Be("hilo");
			hbmGenerator.param[0].name.Should().Be("max_low");
			hbmGenerator.param[0].GetText().Should().Be("100");
			var hbmVersion = hbmClass.Version;
			hbmVersion.name.Should().Be("version");
			var hbmProperty = hbmClass.Properties.OfType<HbmProperty>().Single();
			hbmProperty.name.Should().Be("something");
			hbmProperty.access.Should().Be("field");
			hbmProperty.length.Should().Be("150");
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:32,代码来源:MappingOfPrivateMembersOnRootEntity.cs

示例3: GetMappings

        protected static HbmMapping GetMappings()
        {
            //There is a dynamic way to do this, but for simplicity I chose to hard code
            var mapper = new ModelMapper();

            mapper.AddMapping<UsersMap>();
            var mapping = mapper.CompileMappingFor(new[] { typeof(Users) });
            return mapping;
        }
开发者ID:cyber48,项目名称:Astra,代码行数:9,代码来源:MainWindow.xaml.cs

示例4: WhenIdBagWithOneToManyThenThrow

		public void WhenIdBagWithOneToManyThenThrow()
		{
			var mapper = new ModelMapper();
			mapper.Class<Animal>(map =>
			{
				map.Id(x => x.Id, idmap => { });
				map.IdBag(x => x.Children, bag => { }, rel => rel.OneToMany());
			});
			Assert.That(() => mapper.CompileMappingFor(new[] { typeof(Animal) }), Throws.TypeOf<NotSupportedException>());
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:10,代码来源:IdBagMappingTest.cs

示例5: GetMappings

        private static HbmMapping GetMappings()
        {
            var mapper = new ModelMapper();

            mapper.AddMapping<BlogPostMapping>();
            mapper.AddMapping<CommentMapping>();

            HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(BlogPost), typeof(Comment) });

            return mapping;
        }
开发者ID:drypa,项目名称:BlogSample_v2,代码行数:11,代码来源:NHibernateConfigurator.cs

示例6: WhenDefineEmptyNaturalIdThenNoMapIt

		public void WhenDefineEmptyNaturalIdThenNoMapIt()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(map =>
			{
				map.Id(x => x.Id, idmap => { });
				map.NaturalId(nidm =>{});
			});
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			hbmClass.naturalid.Should().Be.Null();
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:12,代码来源:NaturalIdTests.cs

示例7: ExplicitColumnNameIsAlwaysMapped

		public void ExplicitColumnNameIsAlwaysMapped(string columnName)
		{
			var mapper = new ModelMapper();
			mapper.Class<Foo>(cm => cm.Bag(x => x.Bars,
			 							   bpm => { },
										   cer => cer.ManyToMany(mtmm => mtmm.Column(columnName))));
			var mapping = mapper.CompileMappingFor(new[] { typeof(Foo), typeof(Bar) });
			var hbmClass = mapping.RootClasses.Single(x => x.Name == "Foo");
			var hbmBag = hbmClass.Properties.OfType<HbmBag>().Single();
			var hbmManyToMany = (HbmManyToMany)hbmBag.ElementRelationship;
			Assert.AreEqual(columnName, hbmManyToMany.column);
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:12,代码来源:Fixture.cs

示例8: WhenMapDynCompoPropertiesThenShouldAssignPropertyType

		public void WhenMapDynCompoPropertiesThenShouldAssignPropertyType()
		{
			var mapper = new ModelMapper();
			mapper.Class<Person>(map =>
			{
				map.Id(x => x.Id, idmap => { });
				map.Component(x => x.Info, new { MyInt = 5, MyDate = DateTime.Now }, z => { });
			});

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Person) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmDynamicComponent = hbmClass.Properties.OfType<HbmDynamicComponent>().Single();
			hbmDynamicComponent.Properties.OfType<HbmProperty>().Select(x => x.type1).All(x=> x.Satisfy(value=> !string.IsNullOrEmpty(value)));
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:14,代码来源:DynamicComponentMappingTests.cs

示例9: WhenIdBagWithManyToManyThenMapIt

		public void WhenIdBagWithManyToManyThenMapIt()
		{
			var mapper = new ModelMapper();
			mapper.Class<Animal>(map =>
													 {
														 map.Id(x => x.Id, idmap => { });
														 map.IdBag(x => x.Children, bag => { }, rel=> rel.ManyToMany());
													 });
			var hbmMapping = mapper.CompileMappingFor(new[]{ typeof(Animal)});
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmIdbag = hbmClass.Properties.OfType<HbmIdbag>().SingleOrDefault();
			Assert.That(hbmIdbag, Is.Not.Null);
			Assert.That(hbmIdbag.ElementRelationship, Is.InstanceOf<HbmManyToMany>());
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:14,代码来源:IdBagMappingTest.cs

示例10: WhenMapDynCompoThenMapItAndItsProperties

		public void WhenMapDynCompoThenMapItAndItsProperties()
		{
			var mapper = new ModelMapper();
			mapper.Class<Person>(map =>
			{
				map.Id(x => x.Id, idmap => { });
				map.Component(x => x.Info, new { MyInt = 5, MyDate = DateTime.Now }, z => { });
			});

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Person) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmDynamicComponent = hbmClass.Properties.OfType<HbmDynamicComponent>().SingleOrDefault();
			hbmDynamicComponent.Should().Not.Be.Null();
			hbmDynamicComponent.Properties.Select(x=> x.Name).Should().Have.SameValuesAs("MyInt", "MyDate");
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:15,代码来源:DynamicComponentMappingTests.cs

示例11: MapClassWithIdAndProperty

		public void MapClassWithIdAndProperty()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(ca =>
			{
				ca.Id(x => x.Id, map =>
				{
					map.Column("MyClassId");
					map.Generator(Generators.HighLow, gmap => gmap.Params(new { max_low = 100 }));
				});
				ca.Property(x => x.Something, map => map.Length(150));
			});
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			ModelIsWellFormed(hbmMapping);
		}
开发者ID:KaraokeStu,项目名称:nhibernate-core,代码行数:15,代码来源:BasicMappingOfSimpleClass.cs

示例12: WhenMapClassWithoutIdAndWithoutGeneratorThenTypeShouldHaveValue

		public void WhenMapClassWithoutIdAndWithoutGeneratorThenTypeShouldHaveValue()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(ca => ca.Id(null, map =>
			{
				map.Column("MyClassId");
			}));
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			Assert.That(hbmClass, Is.Not.Null);
			var hbmId = hbmClass.Id;
			Assert.That(hbmId, Is.Not.Null);
			Assert.That(hbmId.column1, Is.EqualTo("MyClassId"));
			Assert.That(hbmId.type1, Is.Not.Null);
		}
开发者ID:KaraokeStu,项目名称:nhibernate-core,代码行数:15,代码来源:BasicMappingOfSimpleClass.cs

示例13: WhenMapDynCompoThenMapItAndItsProperties

		public void WhenMapDynCompoThenMapItAndItsProperties()
		{
			var mapper = new ModelMapper();
			mapper.Class<Person>(map =>
			{
				map.Id(x => x.Id, idmap => { });
				map.Component(x => x.Info, new { MyInt = 5, MyDate = DateTime.Now }, z => { });
			});

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Person) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmDynamicComponent = hbmClass.Properties.OfType<HbmDynamicComponent>().SingleOrDefault();
			Assert.That(hbmDynamicComponent, Is.Not.Null);
			Assert.That(hbmDynamicComponent.Properties.Select(x=> x.Name), Is.EquivalentTo(new [] {"MyInt", "MyDate"}));
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:15,代码来源:DynamicComponentMappingTests.cs

示例14: WhenMapComponentAsIdAttributesThenMapAttributes

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

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

示例15: WhenMapClassWithoutIdAndWithoutGeneratorThenTypeShouldHaveValue

		public void WhenMapClassWithoutIdAndWithoutGeneratorThenTypeShouldHaveValue()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(ca => ca.Id(null, map =>
			{
				map.Column("MyClassId");
			}));
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			hbmClass.Should().Not.Be.Null();
			var hbmId = hbmClass.Id;
			hbmId.Should().Not.Be.Null();
			hbmId.column1.Should().Be("MyClassId");
			hbmId.type1.Should().Not.Be.Null();
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:15,代码来源:BasicMappingOfSimpleClass.cs


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