コード例 #1
0
        public override Configuration Map(Configuration cfg)
        {
            ConventionModelMapper mapper = new ConventionModelMapper();

            mapper.IsEntity((x, y) => this.IsEntity(x, y, this.EntitiesAssemblyName));
            mapper.IsRootEntity((x, y) => this.IsRootEntity(x, y, this.EntitiesAssemblyName));
            mapper.IsOneToMany((x, y) => this.IsOneToMany(x, y));
            mapper.IsManyToOne((x, y) => this.IsManyToOne(x, y));
            mapper.IsManyToMany((x, y) => this.IsManyToMany(x, y));
            mapper.IsBag((x, y) => this.IsBag(x, y));
            mapper.IsSet((x, y) => this.IsSet(x, y));
            mapper.IsProperty((x, y) => this.IsProperty(x, y));
            mapper.IsPersistentProperty((x, y) => this.IsPersistentProperty(x, y));
            mapper.BeforeMapClass      += this.BeforeMapClass;
            mapper.BeforeMapProperty   += this.BeforeMapProperty;
            mapper.BeforeMapSet        += this.BeforeMapSet;
            mapper.BeforeMapOneToMany  += this.BeforeMapOneToMany;
            mapper.BeforeMapManyToOne  += this.BeforeMapManyToOne;
            mapper.BeforeMapManyToMany += BeforeMapManyToMany;

            HbmMapping mappings = mapper.CompileMappingFor(Assembly.Load(this.EntitiesAssemblyName).GetExportedTypes());

            cfg.AddMapping(mappings);

            return(cfg);
        }
コード例 #2
0
        public SagaModelMapper(IEnumerable <Type> typesToScan)
        {
            Mapper = new ConventionModelMapper();

            _sagaEntities =
                typesToScan.Where(t => typeof(IContainSagaData).IsAssignableFrom(t) && !t.IsInterface);

            _entityTypes = GetTypesThatShouldBeAutoMapped(_sagaEntities, typesToScan);

            Mapper.IsTablePerClass((type, b) => false);
            Mapper.IsTablePerConcreteClass((type, b) => _sagaEntities.Contains(type));
            Mapper.IsTablePerClassHierarchy((type, b) => false);
            Mapper.IsEntity((type, mapped) => _entityTypes.Contains(type));
            Mapper.IsArray((info, b) => false);
            Mapper.IsBag((info, b) =>
            {
                var memberType = info.GetPropertyOrFieldType();
                return(typeof(IEnumerable).IsAssignableFrom(memberType) &&
                       !(memberType == typeof(string) || memberType == typeof(byte[]) || memberType.IsArray));
            });
            Mapper.IsPersistentProperty((info, b) => !HasAttribute <RowVersionAttribute>(info));

            Mapper.BeforeMapClass         += ApplyClassConvention;
            Mapper.BeforeMapUnionSubclass += ApplySubClassConvention;
            Mapper.BeforeMapProperty      += ApplyPropertyConvention;
            Mapper.BeforeMapBag           += ApplyBagConvention;
            Mapper.BeforeMapManyToOne     += ApplyManyToOneConvention;
        }
コード例 #3
0
        SagaModelMapper(SagaMetadataCollection allMetadata, IEnumerable <Type> typesToScan, Func <Type, string> tableNamingConvention = null)
        {
            this.tableNamingConvention = tableNamingConvention ?? DefaultTableNameConvention;
            mapper = new ConventionModelMapper();

            this.typesToScan = typesToScan.ToList();

            sagaMetaModel = allMetadata;

            sagaEntities =
                this.typesToScan.Where(t => typeof(IContainSagaData).IsAssignableFrom(t) && !t.IsInterface).ToList();

            PopulateTypesThatShouldBeAutoMapped();

            mapper.IsTablePerClass((type, b) => false);
            mapper.IsTablePerConcreteClass((type, b) => sagaEntities.Contains(type));
            mapper.IsTablePerClassHierarchy((type, b) => false);
            mapper.IsEntity((type, mapped) => entityTypes.Contains(type));
            mapper.IsArray((info, b) => false);
            mapper.IsBag((info, b) =>
            {
                var memberType = info.GetPropertyOrFieldType();
                return(typeof(IEnumerable).IsAssignableFrom(memberType) &&
                       !(memberType == typeof(string) || memberType == typeof(byte[]) || memberType.IsArray));
            });
            mapper.IsPersistentProperty((info, b) => !HasAttribute <RowVersionAttribute>(info));
            mapper.BeforeMapClass         += ApplyClassConvention;
            mapper.BeforeMapUnionSubclass += ApplySubClassConvention;
            mapper.BeforeMapProperty      += ApplyPropertyConvention;
            mapper.BeforeMapBag           += ApplyBagConvention;
            mapper.BeforeMapManyToOne     += ApplyManyToOneConvention;
        }
コード例 #4
0
        public SagaModelMapper(IEnumerable <Type> typesToScan)
        {
            Mapper = new ConventionModelMapper();

            _sagaEntites = typesToScan.Where(t => typeof(ISagaEntity).IsAssignableFrom(t) && !t.IsInterface);

            _entityTypes = GetTypesThatShouldBeAutoMapped(_sagaEntites, typesToScan);

            Mapper.IsEntity((type, b) => _entityTypes.Contains(type));
            Mapper.IsArray((info, b) => false);
            Mapper.IsBag((info, b) =>
            {
                var memberType = info.GetPropertyOrFieldType();
                return(typeof(IEnumerable).IsAssignableFrom(memberType) &&
                       !(memberType == typeof(string) || memberType == typeof(byte[]) || memberType.IsArray));
            });

            Mapper.BeforeMapClass          += ApplyClassConvention;
            Mapper.BeforeMapJoinedSubclass += ApplySubClassConvention;
            Mapper.BeforeMapProperty       += ApplyPropertyConvention;
            Mapper.BeforeMapBag            += ApplyBagConvention;
            Mapper.BeforeMapManyToOne      += ApplyManyToOneConvention;
        }
コード例 #5
0
ファイル: MappingConfig.cs プロジェクト: In1quity/Fountain
        private static HbmMapping ImplicitMapping()
        {
            var mapper = new ConventionModelMapper();

            mapper.IsEntity((t, d) => IsEntity(t));
            mapper.IsRootEntity((t, declared) => IsEntity(t) && !IsEntity(t.BaseType));
            mapper.IsComponent((t, d) => d);
            mapper.IsBag((mi, d) => d);

            mapper.IsPersistentProperty((mi, d) =>
            {
                if (mi.MemberType != MemberTypes.Property)
                {
                    return(false);
                }
                var pi = (PropertyInfo)mi;
                return(pi.CanRead && pi.CanWrite);
            });

            mapper.BeforeMapProperty += (model, member, prop) =>
            {
                var type = member.LocalMember.GetPropertyOrFieldType();
                if (type == typeof(DateTime))
                {
                    prop.Type <UtcDateTimeType>();
                }
                else if (type == typeof(JObject))
                {
                    prop.Type <JObjectType>();
                    prop.Length(65536); // medium clob
                }
            };

            mapper.BeforeMapSet += (model, member, set) =>
            {
                set.Key(k => k.Column(member.GetContainerEntity(model).Name + "Id"));
                set.Cascade(Cascade.All | Cascade.DeleteOrphans);
            };

            mapper.BeforeMapManyToOne += (model, member, mto) =>
            {
                mto.Column(member.LocalMember.Name + "Id");
            };

            mapper.BeforeMapClass += (model, type, cls) =>
            {
                cls.Id(id =>
                {
                    id.Column("Id");
                    id.Generator(Generators.HighLow, g => g.Params(new { max_lo = 100 }));
                });
                cls.Table(type.Name);
                cls.Lazy(false);
            };

            // add conformist mappings
            mapper.AddMappings(Assembly.GetAssembly(typeof(PersistentAttribute)).GetExportedTypes());

            // apply above conventions
            return(mapper.CompileMappingFor(typeof(PersistentAttribute).Assembly.GetExportedTypes().Where(IsEntity)));
        }