本文整理汇总了C#中Mapper.Class方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.Class方法的具体用法?C# Mapper.Class怎么用?C# Mapper.Class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.Class方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefiningAndCustomizingVersionThroughBaseImplementation
public void DefiningAndCustomizingVersionThroughBaseImplementation()
{
// In this example I'll show how you can work with Version and how ConfORM understands OOP
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm, new CoolPatternsAppliersHolder(orm));
// In this case I will use the definition of table-to-class strategy class by class
orm.TablePerClass<CurrencyDefinition>();
orm.TablePerClass<Company>();
orm.TablePerClass<Customer>();
orm.TablePerClass<Provider>();
// Defining relations
orm.OneToOne<Company, Customer>();
orm.OneToOne<Company, Provider>();
// In the follow line I'm defining which is the property used as Version for all classes inherited from VersionedEntity
orm.VersionProperty<VersionedEntity>(ve=> ve.Version);
// In the follow line I'm customizing the column-name for the property used as Version for all classes inherited from VersionedEntity....
// Note : VersionedEntity is not an entity, it is only a base class.
mapper.Class<VersionedEntity>(cm => cm.Version(ve => ve.Version, vm => vm.Column("Revision")));
// In the follow line I'm customizing the column-name for the property used as Version only for the class Provider
// Note : You can move the follow line before the previous and the result does not change, this is because ConfORM can understand
// which is a base customization and which is the specific customization.
mapper.Class<Provider>(cm => cm.Version(ve => ve.Version, vm => vm.Column("IncrementalVersion")));
// Note : I have to create mappings for the whole domain; Entity and VersionedEntity are excluded from de mapping because out-side
// root-entities hierarchy (root-entities are : CurrencyDefinition, Company, Customer, Provider)
var mapping = mapper.CompileMappingFor(typeof(Entity).Assembly.GetTypes().Where(t => t.Namespace == typeof(Entity).Namespace));
Console.Write(mapping.AsString());
}
示例2: CustomizeRelations
private void CustomizeRelations(Mapper mapper)
{
/* TODO: add IDomainInspector.IsOptionalOneToMany to avoid auto OnDelete.Cascade and soft-Cascade actions.
IsOptionalOneToMany may come in place using Declared.Explicit in the ORM */
mapper.Class<User>(cm =>
{
cm.Id(u => u.Id, im => im.Generator(Generators.Foreign<User>(u => u.Human)));
cm.OneToOne(u => u.Human, otom => otom.Constrained(true));
});
mapper.Class<Human>(cm => cm.Bag(human => human.Pets, bagm =>
{
bagm.Cascade(Cascade.None);
bagm.Key(km => km.OnDelete(OnDeleteAction.NoAction));
}, cer => { }));
mapper.Class<Zoo>(cm =>
{
cm.Map(zoo => zoo.Mammals, mapm =>
{
mapm.Cascade(Cascade.None);
mapm.Key(km => km.OnDelete(OnDeleteAction.NoAction));
mapm.Inverse(false);
}, x=> { }, cer => { });
cm.Map(zoo => zoo.Animals, mapm =>
{
mapm.Cascade(Cascade.None);
mapm.Key(km => km.OnDelete(OnDeleteAction.NoAction));
}, x => { }, cer => { });
});
}
示例3: GetMockedDomainInspector
public void WhenCustomizeNestedComponentParentAccessThroughCollectionThenApplyCustomizationToMappingForCompositeElement()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var domainInspector = orm.Object;
var mapper = new Mapper(domainInspector);
mapper.Class<MyClass>(
ca =>
ca.Bag(mycomponent => mycomponent.Components, x => { },
cer =>
cer.Component(
c =>
c.Component(mycomponent => mycomponent.Component,
ce => ce.Parent(mync => mync.Parent, pa => pa.Access(Accessor.Field))))));
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("MyClass"));
var hbmBag = (HbmBag)rc.Properties.First(p => p.Name == "Components");
var hbmCompositeElement = (HbmCompositeElement)hbmBag.ElementRelationship;
var hbmNestedCompositeElement = (HbmNestedCompositeElement)hbmCompositeElement.Properties.First(p => p.Name == "Component");
hbmNestedCompositeElement.Parent.name.Should().Be("Parent");
hbmNestedCompositeElement.Parent.access.Should().Be("field.camelcase-underscore");
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:25,代码来源:NestedComponentAttributesCustomizationTest.cs
示例4: WhenCustomizedAndSpecifiedThenSetDifferentConfigurationForSameComponent
public void WhenCustomizedAndSpecifiedThenSetDifferentConfigurationForSameComponent()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var domainInspector = orm.Object;
var mapper = new Mapper(domainInspector);
mapper.Customize<Name>(name =>
{
name.Property(np => np.First, pm => pm.Length(20));
name.Property(np => np.Last, pm => pm.Length(35));
});
mapper.Class<Person>(c =>
{
c.Component(p => p.RealName, cname => cname.Property(cnp => cnp.Last, pm => pm.Length(50)));
c.Component(p => p.Aka, cname => cname.Property(cnp => cnp.First, pm => pm.Length(50)));
});
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("Person"));
var hbmRealName = (HbmComponent)rc.Properties.First(p => p.Name == "RealName");
var hbmAka = (HbmComponent)rc.Properties.First(p => p.Name == "Aka");
hbmRealName.Properties.OfType<HbmProperty>().Select(p => p.length).Should().Have.SameValuesAs("20", "50");
hbmAka.Properties.OfType<HbmProperty>().Select(p => p.length).Should().Have.SameValuesAs("50", "35");
}
示例5: WhenRegisterCustomizerOnMapKeyManyToManyThenInvokeCustomizer
public void WhenRegisterCustomizerOnMapKeyManyToManyThenInvokeCustomizer()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
var called = false;
mapper.Class<MyClass>(cm=> cm.Map(myClass=> myClass.Dictionary,mpm=> { },mkm=> called= true, cerm=> { }));
mapper.CompileMappingFor(new[] { typeof(MyClass) });
called.Should().Be.True();
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:9,代码来源:MapKeyManyToManyRelationCustomizersCallingTest.cs
示例6: WhenRegisterCustomizerOnMapKeyManyToManyThenInvokeCustomizerActions
public void WhenRegisterCustomizerOnMapKeyManyToManyThenInvokeCustomizerActions()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
mapper.Class<MyClass>(cm => cm.Map(myClass => myClass.Dictionary, mpm => { }, mkm => mkm.ManyToMany(mtm => mtm.Column("RelationId")), cerm => { }));
var mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
var rc = mapping.RootClasses.Single();
var hbmMap = rc.Properties.OfType<HbmMap>().Single();
var hbmMapKeyManyToMany = (HbmMapKeyManyToMany) hbmMap.Item;
hbmMapKeyManyToMany.column.Should().Be("RelationId");
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:11,代码来源:MapKeyManyToManyRelationCustomizersCallingTest.cs
示例7: WhenRegisteredCustomizerForSetThenCallElementMapperAction
public void WhenRegisteredCustomizerForSetThenCallElementMapperAction()
{
var orm = GetBaseMockedDomainInspector();
orm.Setup(x => x.IsSet(It.Is<MemberInfo>(m => m == ForClass<Person>.Property(p => p.Pets)))).Returns(true);
var called = false;
var mapper = new Mapper(orm.Object);
mapper.Class<Person>(cm => cm.Set(person => person.Pets, cpm => { }, cerm => cerm.OneToMany(em => called = true)));
mapper.CompileMappingFor(new[] { typeof(Person) });
called.Should().Be.True();
}
示例8: CanCustomize
public void CanCustomize()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var domainInspector = orm.Object;
var mapper = new Mapper(domainInspector);
mapper.Class<MyClass>(cm => cm.NaturalId(nidm => nidm.Mutable(true)));
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
HbmClass rc = mapping.RootClasses.Single();
rc.naturalid.mutable.Should().Be.True();
}
示例9: WhenCustomizedInterfaceThenWorkForConcreteImplementations
public void WhenCustomizedInterfaceThenWorkForConcreteImplementations()
{
var orm = new ObjectRelationalMapper();
// Mark the version property using the interface
orm.VersionProperty<IVersionedEntity>(x => x.Version);
orm.VersionProperty<ITimeVersionedEntity>(x => x.UpdatedAt);
var rootEntities = new[] { typeof(MyEntity), typeof(MyOtherEntity) };
orm.TablePerClass(rootEntities);
var mapper = new Mapper(orm);
// customize base entities
mapper.Class<IVersionedEntity>(cm => cm.Version(x => x.Version, vm => vm.Column("Revision")));
mapper.Class<ITimeVersionedEntity>(cm => cm.Version(x => x.UpdatedAt, vm =>
{
vm.Column(column =>
{
column.Name("LastUpdate");
column.NotNullable(true);
column.SqlType("timestamp");
});
vm.Generated(VersionGeneration.Always);
}));
var mappings = mapper.CompileMappingFor(rootEntities);
HbmClass hbmMyEntity = mappings.RootClasses.Single(hbm => hbm.Name == "MyEntity");
hbmMyEntity.Version.Should().Not.Be.Null();
hbmMyEntity.Version.name.Should().Be("Version");
hbmMyEntity.Version.column1.Should().Be("Revision");
HbmClass hbmMyOtherEntity = mappings.RootClasses.Single(hbm => hbm.Name == "MyOtherEntity");
hbmMyOtherEntity.Version.Should().Not.Be.Null();
hbmMyOtherEntity.Version.name.Should().Be("UpdatedAt");
hbmMyOtherEntity.Version.Columns.Single().name.Should().Be("LastUpdate");
hbmMyOtherEntity.Version.generated.Should().Be(HbmVersionGeneration.Always);
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:40,代码来源:VersionInterfacePolymorphicCustomizationTest.cs
示例10: WhenAddMetaTypeThenSetIdMetaTypeWithGiveIdMetaType
public void WhenAddMetaTypeThenSetIdMetaTypeWithGiveIdMetaType()
{
var orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
mapper.Class<MyClass>(cm => cm.Any(myclass => myclass.OtherReferenceClass, typeof(string), am =>
{
am.MetaValue("A", typeof (MyReferenceClass));
}));
var mappings = mapper.CompileMappingFor(new[] { typeof(MyClass) });
var hbmClass = mappings.RootClasses.Single();
var hbmAny = (HbmAny)hbmClass.Properties.Single(p => p.Name == "OtherReferenceClass");
hbmAny.idtype.Should().Be("String");
}
示例11: WhenCustomizeComponentKeyPropertyThenInvokeCustomizers
public void WhenCustomizeComponentKeyPropertyThenInvokeCustomizers()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
mapper.Class<Person>(cm=> cm.Map(person=> person.Skills,mpm=> { }, mkm=>
{
mkm.Component(ckm=> ckm.Property(toySkill=> toySkill.Level, pm=> pm.Column("myLevelColumn")));
}, cerm=> { }));
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
var rc = mapping.RootClasses.Single();
var map = rc.Properties.OfType<HbmMap>().Single();
var hbmCompositeMapKey = (HbmCompositeMapKey)map.Item;
var hbmKeyProperty = (HbmKeyProperty) hbmCompositeMapKey.Properties.Single(p => p.Name == "Level");
hbmKeyProperty.Columns.Single().name.Should().Be("myLevelColumn");
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:15,代码来源:MapKeyComponentRelationCustomizersCallingTest.cs
示例12: WhenCustomizeAccessorForComponentThenMapToField
public void WhenCustomizeAccessorForComponentThenMapToField()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var domainInspector = orm.Object;
var mapper = new Mapper(domainInspector);
mapper.Class<MyClass>(cm=> cm.Component(myclass=> myclass.ComponentLevel0, compo=> compo.Access(Accessor.Field)));
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("MyClass"));
var relation = rc.Properties.First(p => p.Name == "ComponentLevel0");
relation.Should().Be.OfType<HbmComponent>();
var component = (HbmComponent)relation;
component.access.Should().Contain("field");
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:16,代码来源:ComponentPropertyAccessorCustomizationTest.cs
示例13: WhenExplicitRequiredThroughClassCustomizerApplyCascadeOnParent
public void WhenExplicitRequiredThroughClassCustomizerApplyCascadeOnParent()
{
var orm = new ObjectRelationalMapper();
orm.TablePerClass<Node>();
var mapper = new Mapper(orm);
mapper.Class<Node>(node => node.ManyToOne(n => n.Parent, m => m.Cascade(Cascade.Persist)));
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Node) });
HbmClass rc = mapping.RootClasses.Single();
var parent = (HbmManyToOne)rc.Properties.Single(p => p.Name == "Parent");
parent.cascade.Should().Contain("persist");
var subNodes = (HbmBag)rc.Properties.Single(p => p.Name == "Subnodes");
subNodes.cascade.Should().Contain("all").And.Contain("delete-orphan");
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:16,代码来源:BidirectionalOneToManyCascadeCircularIntegrationTest.cs
示例14: WhenCustomizeNestedComponetPerPropertyThenEachPropertyInDifferentWays
public void WhenCustomizeNestedComponetPerPropertyThenEachPropertyInDifferentWays()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var domainInspector = orm.Object;
var mapper = new Mapper(domainInspector);
mapper.Class<MyClass>(cm =>
{
cm.Component(myclass => myclass.ComponentLevel00, compo00 => compo00.Component(c => c.ComponentLevel1, compo00_1 => compo00_1.Lazy(true)));
cm.Component(myclass => myclass.ComponentLevel01, compo01 => compo01.Component(c => c.ComponentLevel1, compo00_1 => compo00_1.Lazy(false)));
});
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("MyClass"));
var relation0 = ((HbmComponent)rc.Properties.First(p => p.Name == "ComponentLevel00")).Properties.First(p => p.Name == "ComponentLevel1");
relation0.IsLazyProperty.Should().Be.True();
var relation1 = ((HbmComponent)rc.Properties.First(p => p.Name == "ComponentLevel01")).Properties.First(p => p.Name == "ComponentLevel1");
relation1.IsLazyProperty.Should().Be.False();
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:20,代码来源:ComponentAttributesCustomizationByPropertyPath.cs
示例15: AppliesGeneralConventions
private void AppliesGeneralConventions(Mapper mapper)
{
const string softDeleteWhereClause = "DeletedOn is NULL";
// because VersionModelBase is not an entity I can use the it to customize the mapping of all inherited classes
mapper.Class<VersionModelBase>(map => map.Where(softDeleteWhereClause));
// When the collection elements inherits from VersionModelBase then should apply the where-clause for "soft delete"
mapper.AddCollectionPattern(mi => mi.GetPropertyOrFieldType().IsGenericCollection() &&
typeof (VersionModelBase).IsAssignableFrom(
mi.GetPropertyOrFieldType().DetermineCollectionElementType())
, map => map.Where(softDeleteWhereClause));
// The default length for string is 100
// Note : because this convetion has no specific restriction other than typeof(string) should be added at first (the order, in this case, is important)
mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(string), map => map.Length(100));
// When the property name is Description and is of type string then apply length 500
mapper.AddPropertyPattern(mi => mi.Name == "Description" && mi.GetPropertyOrFieldType() == typeof (string),
map => map.Length(500));
// When the property is of type decimal and it refers to a price then applies Currency
mapper.AddPropertyPattern(mi => mi.Name.EndsWith("Cost") && mi.GetPropertyOrFieldType() == typeof (decimal),
map => map.Type(NHibernateUtil.Currency));
}