Beispiel #1
0
 public void MapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper map)
 {
     map.Table(Service.Pluralize(type.Name));
     map.Key(x =>
     {
         x.ForeignKey(string.Format("fk_{0}_{1}",
                                    type.BaseType.Name,
                                    type.Name));
         x.Column(type.Name + "Id");
     });
 }
        private static void JoinedSubclassConvention(IModelInspector modelInspector,
                                                     Type type,
                                                     IJoinedSubclassAttributesMapper joinedSubclassAttributesMapper)
        {
            var schema = IdentityBuilder.BuildSchema(type.Namespace);

            joinedSubclassAttributesMapper.Schema(schema);

            var tableName = IdentityBuilder.BuildTableName(type.Name);

            joinedSubclassAttributesMapper.Table(tableName);

            joinedSubclassAttributesMapper.Key(km => km.Column(string.Concat(type.Name,
                                                                             ConventionNames.PrimaryKeyPostfix)));
        }
Beispiel #3
0
        private void ApplySubClassConvention(IModelInspector mi, Type type, IJoinedSubclassAttributesMapper map)
        {
            map.Key(keyMapping => keyMapping.Column(String.Format("{0}_id", type.BaseType.Name)));

            var tableAttribute = GetAttribute <TableNameAttribute>(type);

            if (tableAttribute != null)
            {
                map.Table(tableAttribute.TableName);
                if (!String.IsNullOrEmpty(tableAttribute.Schema))
                {
                    map.Schema(tableAttribute.Schema);
                }
            }
        }
        //6.0 TODO: Merge to IJoinedSubclassAttributesMapper<TEntity>
        public static void Extends <TEntity>(this IJoinedSubclassAttributesMapper <TEntity> mapper, string entityOrClassName)
            where TEntity : class
        {
            switch (mapper)
            {
            case JoinedSubclassCustomizer <TEntity> jsc:
                jsc.Extends(entityOrClassName);
                break;

            case PropertyContainerCustomizer <TEntity> pcc:
                pcc.CustomizersHolder.AddCustomizer(
                    typeof(TEntity),
                    (IJoinedSubclassAttributesMapper m) => m.Extends(entityOrClassName));
                break;

            default:
                throw new ArgumentException($@"{mapper.GetType()} requires to extend {typeof(JoinedSubclassCustomizer<TEntity>).FullName} or {typeof(PropertyContainerCustomizer<TEntity>).FullName} to support Extends(entityOrClassName).");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Maps a joined subclass inheritance hierarchy
        /// </summary>
        /// <param name="modelInspector">The model inspector</param>
        /// <param name="type">The entity type</param>
        /// <param name="mapper">The joined subclass mapper</param>
        private void MapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper mapper)
        {
            Type entityType = type.UnderlyingSystemType;
            Type baseType   = type.GetBaseTypes().FirstOrDefault(t => IsEntity(t));

            string schemaName           = namingEngine.ToSchemaName(entityType);
            string tableName            = namingEngine.ToTableName(entityType);
            var    idProperty           = modelInspector.GetIdentifierMember(entityType);
            string foreignKeyColumnName = namingEngine.ToForeignKeyColumnName(baseType, idProperty);
            string foreignKeyName       = namingEngine.ToForeignKeyName(entityType, baseType, entityType, idProperty);

            // Mapping
            mapper.Schema(schemaName);
            mapper.Table(tableName);
            mapper.Key(k =>
            {
                k.Column(foreignKeyColumnName);
                k.ForeignKey(foreignKeyName);
            });
        }
Beispiel #6
0
 private void MapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper map)
 {
     if (Pluralize)
     {
         map.Table(service.Pluralize(type.Name));
     }
     if (IdFkConstraintNaming != null)
     {
         foreach (var idProperty in type.GetProperties().Where(modelInspector.IsPersistentId))
         {
             map.Key(x =>
             {
                 x.ForeignKey(IdFkConstraintNaming(type));
                 if (IdColumnNaming != null)
                 {
                     x.Column(IdColumnNaming(type, idProperty));
                 }
             });
         }
     }
 }
Beispiel #7
0
 public static void MapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper map)
 {
 }
        public static void DefaultSubclassMapper(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper mapper)
        {
            MapSchema(mapper.Schema, type);

            mapper.Key(key =>
            {
                key.Column(type.BaseType.Name + _foreignKeyColumnPostfix);
            });
        }
        protected override void OnBeforeMapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
        {
            joinedSubclassCustomizer.Key(
                k =>
                {
                    k.Column(GetKeyColumnName(modelInspector, type.BaseType ?? type, false));
                    if (type.BaseType != null)
                    {
                        k.ForeignKey(string.Format("FK_{0}_{1}", type.Name, type.BaseType.Name));
                    }
                });

            joinedSubclassCustomizer.Table(GetTableName(modelInspector, type));
        }
 protected virtual void OnBeforeMapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
 {
 }
Beispiel #11
0
 private static void PluralizeTableName(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
 {
     joinedSubclassCustomizer.Table(type.Pluralize());
 }
Beispiel #12
0
 private static void NameKeyColumnId(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
 {
     joinedSubclassCustomizer.Key(key => key.Column("Id"));
 }
 //6.0 TODO: Merge to IJoinedSubclassAttributesMapper
 public static void Extends(this IJoinedSubclassAttributesMapper mapper, string entityOrClassName)
 {
     ReflectHelper.CastOrThrow <JoinedSubclassMapper>(mapper, "Extends(entityOrClassName)").Extends(entityOrClassName);
 }
Beispiel #14
0
 protected virtual void OnAfterMapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
 {
 }
        protected override void OnBeforeMapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper joinedSubclassCustomizer)
        {
            joinedSubclassCustomizer.Key(
                k =>
            {
                k.Column(GetKeyColumnName(modelInspector, type.BaseType ?? type, false));
                if (type.BaseType != null)
                {
                    k.ForeignKey(string.Format("FK_{0}_{1}", type.Name, type.BaseType.Name));
                }
            });

            joinedSubclassCustomizer.Table(GetTableName(modelInspector, type));
        }
        /// <summary>
        /// Maps a joined subclass inheritance hierarchy
        /// </summary>
        /// <param name="modelInspector">The model inspector</param>
        /// <param name="type">The entity type</param>
        /// <param name="mapper">The joined subclass mapper</param>
        private void MapJoinedSubclass(IModelInspector modelInspector, Type type, IJoinedSubclassAttributesMapper mapper)
        {
            Type entityType = type.UnderlyingSystemType;
            Type baseType = type.GetBaseTypes().FirstOrDefault(t => IsEntity(t));

            string schemaName = namingEngine.ToSchemaName(entityType);
            string tableName = namingEngine.ToTableName(entityType);
            var idProperty = modelInspector.GetIdentifierMember(entityType);
            string foreignKeyColumnName = namingEngine.ToForeignKeyColumnName(baseType, idProperty);
            string foreignKeyName = namingEngine.ToForeignKeyName(entityType, baseType, entityType, idProperty);

            // Mapping
            mapper.Schema(schemaName);
            mapper.Table(tableName);
            mapper.Key(k =>
                {
                    k.Column(foreignKeyColumnName);
                    k.ForeignKey(foreignKeyName);
                });
        }
 public void InvokeCustomizers(System.Type type, IJoinedSubclassAttributesMapper mapper)
 {
     InvokeCustomizers(joinedClassCustomizers, type, mapper);
 }