本文整理汇总了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();
}
示例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");
}
示例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;
}
示例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>());
}
示例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;
}
示例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();
}
示例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);
}
示例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)));
}
示例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>());
}
示例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");
}
示例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);
}
示例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);
}
示例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"}));
}
示例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");
}
示例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();
}