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"); })); }
public void AddCustomDelegatedManyToOneApplierWithMember() { var orm = new Mock <IDomainInspector>(); var mapper = new Mapper(orm.Object); var previousManyToOneApplierCount = mapper.PatternsAppliers.ManyToOne.Count; mapper.AddManyToOnePattern(mi => true, (mi, cm) => { }); mapper.PatternsAppliers.ManyToOne.Count.Should().Be(previousManyToOneApplierCount + 1); }
public void AddSimpleCustomDelegatedManyToOneApplierWithMember() { var orm = new Mock<IDomainInspector>(); var mapper = new Mapper(orm.Object); var previousManyToOneApplierCount = mapper.PatternsAppliers.ManyToOne.Count; mapper.AddManyToOnePattern(mi => true, cm => { }); mapper.PatternsAppliers.ManyToOne.Count.Should().Be(previousManyToOneApplierCount + 1); }
public void CallPatternAppliersOnNestedCompositeElements() { Mock <IDomainInspector> orm = GetMockedDomainInspector(); var mapper = new Mapper(orm.Object); bool reSimplePropertyCalled = false; bool reManyToOneCalled = false; mapper.AddPropertyPattern(mi => mi.DeclaringType == typeof(MyNestedComponent), pm => reSimplePropertyCalled = true); mapper.AddManyToOnePattern(mi => mi.DeclaringType == typeof(MyNestedComponent), pm => reManyToOneCalled = true); mapper.CompileMappingFor(new[] { typeof(MyClass) }); reSimplePropertyCalled.Should().Be.True(); reManyToOneCalled.Should().Be.True(); }
public void WhenRegisterApplierOnManyToOneThenInvokeApplier() { Mock<IDomainInspector> orm = GetMockedDomainInspector(); var mapper = new Mapper(orm.Object); mapper.AddManyToOnePattern(mi=> mi.GetPropertyOrFieldType() == typeof(Skill), mtom=> mtom.Column("SkillId")); 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 hbmKeyManyToOne = (HbmKeyManyToOne)hbmCompositeMapKey.Properties.Single(p => p.Name == "Skill"); hbmKeyManyToOne.Columns.Single().name.Should().Be("SkillId"); }
public void CallPatternAppliersOnNestedCompositeElements() { Mock<IDomainInspector> orm = GetMockedDomainInspector(); var mapper = new Mapper(orm.Object); bool reSimplePropertyCalled = false; bool reManyToOneCalled = false; mapper.AddPropertyPattern(mi => mi.DeclaringType == typeof(MyNestedComponent), pm => reSimplePropertyCalled = true); mapper.AddManyToOnePattern(mi => mi.DeclaringType == typeof(MyNestedComponent), pm => reManyToOneCalled = true); mapper.CompileMappingFor(new[] { typeof(MyClass) }); reSimplePropertyCalled.Should().Be.True(); reManyToOneCalled.Should().Be.True(); }
public void WhenRegisterApplierOnManyToOneThenInvokeApplier() { Mock <IDomainInspector> orm = GetMockedDomainInspector(); var mapper = new Mapper(orm.Object); mapper.AddManyToOnePattern(mi => mi.GetPropertyOrFieldType() == typeof(Skill), mtom => mtom.Column("SkillId")); 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 hbmKeyManyToOne = (HbmKeyManyToOne)hbmCompositeMapKey.Properties.Single(p => p.Name == "Skill"); hbmKeyManyToOne.Columns.Single().name.Should().Be("SkillId"); }
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"); })); }