Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        private HbmMapping Act(Mock <IDomainInspector> orm)
        {
            var mapper = new Mapper(orm.Object);

            mapper.AddCollectionPattern(mi => true, cm => cm.BatchSize(25));
            return(mapper.CompileMappingFor(new[] { typeof(MyClass) }));
        }
Esempio n. 3
0
        public void AddCustomDelegatedApplier()
        {
            var orm    = new Mock <IDomainInspector>();
            var mapper = new Mapper(orm.Object);
            var previousCollectionApplierCount = mapper.PatternsAppliers.Collection.Count;

            mapper.AddCollectionPattern(mi => true, cm => cm.BatchSize(25));

            mapper.PatternsAppliers.Collection.Count.Should().Be(previousCollectionApplierCount + 1);
        }
        public void AddCustomDelegatedApplierWithMember()
        {
            var orm = new Mock<IDomainInspector>();
            var mapper = new Mapper(orm.Object);
            var previousCollectionApplierCount = mapper.PatternsAppliers.Collection.Count;

            mapper.AddCollectionPattern(mi => true, (mi, cm) => cm.BatchSize(25));

            mapper.PatternsAppliers.Collection.Count.Should().Be(previousCollectionApplierCount + 1);
        }
        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));
        }
 private HbmMapping Act(Mock<IDomainInspector> orm)
 {
     var mapper = new Mapper(orm.Object);
     mapper.AddCollectionPattern(mi => true, cm => cm.BatchSize(25));
     return mapper.CompileMappingFor(new[] { typeof(MyClass) });
 }