本文整理汇总了C#中Mapper.Customize方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.Customize方法的具体用法?C# Mapper.Customize怎么用?C# Mapper.Customize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.Customize方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallCustomizerOnCompositeElementsProperties
public void CallCustomizerOnCompositeElementsProperties()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
bool simplePropertyCalled = false;
bool manyToOneCalled = false;
bool reSimplePropertyCalled = false;
bool reManyToOneCalled = false;
mapper.Customize<MyComponent>(x =>
{
x.Property(mc => mc.Simple, pm => simplePropertyCalled = true);
x.ManyToOne(mc => mc.ManyToOne, pm => manyToOneCalled = true);
});
mapper.Customize<MyNestedComponent>(x =>
{
x.Property(mc => mc.ReSimple, pm => reSimplePropertyCalled = true);
x.ManyToOne(mc => mc.ReManyToOne, pm => reManyToOneCalled = true);
});
mapper.CompileMappingFor(new[] { typeof(MyClass) });
simplePropertyCalled.Should().Be.True();
manyToOneCalled.Should().Be.True();
reSimplePropertyCalled.Should().Be.True();
reManyToOneCalled.Should().Be.True();
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:26,代码来源:CustomizerCallingOnCompositeElementTest.cs
示例2: ComposingPatternsAppliersPacks
public void ComposingPatternsAppliersPacks()
{
// Thanks to Lorenzo Vegetti to provide the domain of this example.
// This example refers to a little-domain, interesting from the point of view of mapping with ConfORM.
// Here you can see how apply general convetion, how and when compose patterns-appliers-packs and patterns-appliers,
// how ConfORM can apply different mapping depending on the type of enum (see the difference on CostOptions) and so on...
// You don't have to organize the mapping all in one class, as in this example, and you don't have to use the IModuleMapping...
// You can organize the mapping as you feel more confortable for your application; in some case a class is enough, in other cases would
// be better the separation per module/concern, you are not closed in "mapping per class" box.
var orm = new ObjectRelationalMapper();
// With the follow line I'm adding the pattern for the POID strategy ("native" instead the default "High-Low")
orm.Patterns.PoidStrategies.Add(new NativePoidPattern());
// composition of patterns-appliers-packs and patterns-appliers for Lorenzo's domain
// Note: for bidirectional-one-to-many association Lorenzo is not interested in the default cascade behavior,
// implemented in the BidirectionalOneToManyRelationPack, because he is using a sort of soft-delete in his base class VersionModelBase.
// He can implements a custom pack of patterns-appliers to manage the situation when classes does not inherits from VersionModelBase by the way
// he don't want the cascade atall, so the BidirectionalOneToManyInverseApplier will be enough
IPatternsAppliersHolder patternsAppliers =
(new SafePropertyAccessorPack())
.Merge(new OneToOneRelationPack(orm))
.Merge(new BidirectionalManyToManyRelationPack(orm))
.Merge(new DiscriminatorValueAsClassNamePack(orm))
.Merge(new CoolColumnsNamingPack(orm))
.Merge(new TablePerClassPack())
.Merge(new PluralizedTablesPack(orm, new EnglishInflector()))
.Merge(new ListIndexAsPropertyPosColumnNameApplier())
.Merge(new BidirectionalOneToManyInverseApplier(orm))
.Merge(new EnumAsStringPack())
.Merge(new DatePropertyByNameApplier())
.Merge(new MsSQL2008DateTimeApplier());
// Instancing the Mapper using the result of Merge
var mapper = new Mapper(orm, patternsAppliers);
// Setting the version property using the base class
orm.VersionProperty<VersionModelBase>(v => v.Version);
// Note: I'm declaring the strategy only for the base entity
orm.TablePerClassHierarchy<Cost>();
orm.TablePerClass<EditionQuotation>();
orm.TablePerClass<ProductQuotation>();
orm.TablePerClass<Quotation>();
AppliesGeneralConventions(mapper);
// EditionQuotation.PrintCost don't use lazy-loading
mapper.Customize<EditionQuotation>(map => map.ManyToOne(eq => eq.PrintCost, m2o => m2o.Lazy(LazyRelation.NoLazy)));
// Customizes some others DDL's stuff outside conventions
CustomizeColumns(mapper);
// Note : I have to create mappings for the whole domain
HbmMapping mapping =
mapper.CompileMappingFor(
typeof (GenericModelBase<>).Assembly.GetTypes().Where(t => t.Namespace == typeof (GenericModelBase<>).Namespace));
Console.Write(mapping.AsString());
}
示例3: 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");
}
示例4: WhenCustomizePropertyOnInterfaceAndOverrideOnImplThenApplyCustomizationOnImplementations
public void WhenCustomizePropertyOnInterfaceAndOverrideOnImplThenApplyCustomizationOnImplementations()
{
var orm = new ObjectRelationalMapper();
orm.TablePerClass<MyClass1>();
orm.TablePerClass<MyClass2>();
var mapper = new Mapper(orm);
mapper.Customize<IHasMessage>(x => x.Property(hasMessage => hasMessage.Message, pm => pm.Length(123)));
mapper.Customize<MyClass2>(x => x.Property(hasMessage => hasMessage.Message, pm => pm.Length(456)));
var mappings = mapper.CompileMappingFor(new[] { typeof(MyClass1), typeof(MyClass2) });
HbmClass hbmMyClass1 = mappings.RootClasses.Single(hbm => hbm.Name == "MyClass1");
hbmMyClass1.Properties.OfType<HbmProperty>().Where(p => p.Name == "Message").Single().length.Should().Be("123");
HbmClass hbmMyClass2 = mappings.RootClasses.Single(hbm => hbm.Name == "MyClass2");
hbmMyClass2.Properties.OfType<HbmProperty>().Where(p => p.Name == "Message").Single().length.Should().Be("456");
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:18,代码来源:InterfacePropertiesPolymorphicCustomizationTest.cs
示例5: InitMappings
/// <summary>
/// Initializes the mappings.
/// </summary>
/// <param name="orm">The orm.</param>
/// <param name="mapper">The mapper.</param>
public void InitMappings(ObjectRelationalMapper orm, Mapper mapper)
{
// list all the entities we want to map.
IEnumerable<Type> baseEntities = ListOfModelTypes();
// we map non Content classes as normal
orm.TablePerClass(baseEntities);
orm.Poid<AppSetting>(item => item.Id);
mapper.Customize<AppSetting>(mapping => mapping.Property(item => item.Value, pm => pm.Length(255)));
mapper.Customize<User>(mapping =>
{
mapping.Property(item => item.Email, pm => pm.Unique(true));
mapping.Property(item => item.Password, pm => pm.Length(64));
});
orm.ExcludeProperty<User>(item => item.IsAuthenticated);
orm.ExcludeProperty<User>(item => item.AuthenticationType);
}
示例6: CanCustomizePropertiesOfSauteedEntitiesThroughGenericCustomizer
public void CanCustomizePropertiesOfSauteedEntitiesThroughGenericCustomizer()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var domainInspector = orm.Object;
var mapper = new Mapper(domainInspector);
mapper.Customize<Hinherited2>(ca => ca.Property(h2 => h2.Surname, pm => pm.Length(10)));
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Hinherited), typeof(Hinherited2), typeof(EntitySimple) });
var hbmclass = mapping.JoinedSubclasses.Single();
var hbmProperty = hbmclass.Properties.OfType<HbmProperty>().Where(p => p.Name == "Surname").Single();
hbmProperty.length.Should().Be("10");
}
示例7: WhenCustomizeComponentKeyPropertyUsingGenericCustomizerThenInvokeCustomizers
public void WhenCustomizeComponentKeyPropertyUsingGenericCustomizerThenInvokeCustomizers()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
mapper.Customize<ToySkill>(pcc => pcc.Property(toySkill => toySkill.Level, pm => pm.Column("myLevelColumn")));
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,代码行数:14,代码来源:MapKeyComponentRelationCustomizersCallingTest.cs
示例8: ConfigureMapping
public override void ConfigureMapping(NHibernate.Cfg.Configuration configuration)
{
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm);
mapper.AddPropertyPattern(mi => TypeExtensions.GetPropertyOrFieldType(mi) == typeof(string), pm => pm.Length(50));
orm.Patterns.PoidStrategies.Add(new NativePoidPattern());
orm.Patterns.PoidStrategies.Add(new GuidOptimizedPoidPattern());
// list all the entities we want to map.
IEnumerable<Type> baseEntities = GetMappingTypes();
// we map all classes as Table per class
orm.TablePerClass(baseEntities);
mapper.Customize<Hotel>(ca => ca.Collection(item => item.Reservations, cm => cm.Key(km => km.Column("HotelId"))));
mapper.Customize<Room>(ca => ca.Collection(item => item.Reservations, cm => cm.Key(km =>
{
km.Column("RoomId");
km.OnDelete(OnDeleteAction.NoAction);
})));
mapper.Customize<Reservation>(ca =>
{
ca.ManyToOne(item => item.Hotel, m => { m.Column("HotelId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy); });
ca.ManyToOne(item => item.Room, m => { m.Column("RoomId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy); });
});
// compile the mapping for the specified entities
HbmMapping mappingDocument = mapper.CompileMappingFor(baseEntities);
// inject the mapping in NHibernate
configuration.AddDeserializedMapping(mappingDocument, "Domain");
// fix up the schema
SchemaMetadataUpdater.QuoteTableAndColumns(configuration);
SessionFactory.SessionFactoryInstance = configuration.BuildSessionFactory();
}
示例9: WhenExplicitRequiredApplyCascadeOnParent
public void WhenExplicitRequiredApplyCascadeOnParent()
{
var orm = new ObjectRelationalMapper();
orm.TablePerClass<Node>();
var mapper = new Mapper(orm);
mapper.Customize<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
示例10: WhenCustomizedBaseClassThenWorkInInherited
public void WhenCustomizedBaseClassThenWorkInInherited()
{
var orm = new ObjectRelationalMapper();
orm.TablePerClass<MyEntity>();
var mapper = new Mapper(orm);
// customize base entities
mapper.Customize<Entity>(cm => cm.Property(x => x.CreationDate, pm => pm.Update(false)));
var mappings = mapper.CompileMappingFor(new[] { typeof(MyEntity) });
HbmClass hbmMyEntity = mappings.RootClasses.Single(hbm => hbm.Name == "MyEntity");
var creationDateProp = hbmMyEntity.Properties.OfType<HbmProperty>().Single(p => p.Name == "CreationDate");
creationDateProp.update.Should().Be.False();
creationDateProp.updateSpecified.Should().Be.True();
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:17,代码来源:PropertyPolymorphicCustomizationTest.cs
示例11: WhenCustomizePerPropertyThenEachPropertyInDifferentWays
public void WhenCustomizePerPropertyThenEachPropertyInDifferentWays()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var domainInspector = orm.Object;
var mapper = new Mapper(domainInspector);
mapper.Customize<MyClass>(cm =>
{
cm.Component(myclass => myclass.ComponentLevel00, compo => compo.Lazy(true));
cm.Component(myclass => myclass.ComponentLevel01, compo => compo.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");
relation0.IsLazyProperty.Should().Be.True();
var relation1 = (HbmComponent)rc.Properties.First(p => p.Name == "ComponentLevel01");
relation1.IsLazyProperty.Should().Be.False();
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:20,代码来源:ComponentAttributesCustomizationByPropertyPath.cs
示例12: CallCustomizerOfEachProperty
public void CallCustomizerOfEachProperty()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
bool simplePropertyCalled = false;
bool bagCalled = false;
bool listCalled = false;
bool setCalled = false;
bool mapCalled = false;
bool manyToOneCalled = false;
bool oneToOneCalled = false;
bool anyCalled = false;
bool componentCalled = false;
mapper.Customize<MyClass>(x =>
{
x.Property(mc => mc.SimpleProperty, pm => simplePropertyCalled = true);
x.Collection(mc => mc.Bag, pm => bagCalled = true);
x.Collection(mc => mc.List, pm => listCalled = true);
x.Collection(mc => mc.Set, pm => setCalled = true);
x.Collection(mc => mc.Map, pm => mapCalled = true);
x.ManyToOne(mc => mc.ManyToOne, pm => manyToOneCalled = true);
x.OneToOne(mc => mc.OneToOne, pm => oneToOneCalled = true);
x.Any(mc => mc.Any, pm => anyCalled = true);
x.Component(mc => mc.Component, pm => componentCalled = true);
});
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
simplePropertyCalled.Should().Be.True();
bagCalled.Should().Be.True();
listCalled.Should().Be.True();
setCalled.Should().Be.True();
mapCalled.Should().Be.True();
manyToOneCalled.Should().Be.True();
oneToOneCalled.Should().Be.True();
anyCalled.Should().Be.True();
componentCalled.Should().Be.True();
}
示例13: CustomizeColumns
private void CustomizeColumns(Mapper mapper)
{
// in EditionQuotation all references to a class inherited from Cost are not nullables (this is only an example because you can do it one by one)
mapper.AddManyToOnePattern(
mi => mi.DeclaringType == typeof (EditionQuotation) && typeof (Cost).IsAssignableFrom(mi.GetPropertyOrFieldType()),
map => map.NotNullable(true));
// in Quotation all string properties are not nullables (this is only an example because you can do it one by one)
mapper.AddPropertyPattern(
mi => mi.DeclaringType == typeof (Quotation) && mi.GetPropertyOrFieldType() == typeof (string),
map => map.NotNullable(true));
// Quotation columns size customization (if you use a Validator framework you can implements a pattern-applier to customize columns size and "nullable" stuff)
// Note: It is needed only for properties without a convention (the property Description has its convetion)
mapper.Customize<Quotation>(map =>
{
map.Property(q => q.Code, pm => pm.Length(10));
map.Property(q => q.Reference, pm => pm.Length(50));
map.Property(q => q.PaymentMethod, pm => pm.Length(50));
map.Property(q => q.TransportMethod, pm => pm.Length(50));
});
// Column customization for class ProductQuotation
// Note: It is needed only for properties outside conventions
mapper.Customize<ProductQuotation>(map => map.Property(pq => pq.Group, pm =>
{
pm.Length(50);
pm.Column("GroupName");
}));
}