/// <summary>
 ///     Called after an entity type is added to the model if it has an attribute.
 /// </summary>
 /// <param name="entityTypeBuilder"> The builder for the entity type. </param>
 /// <param name="attribute"> The attribute. </param>
 /// <param name="context"> Additional information associated with convention execution. </param>
 protected override void ProcessEntityTypeAdded(
     IConventionEntityTypeBuilder entityTypeBuilder,
     TableAttribute attribute,
     IConventionContext <IConventionEntityTypeBuilder> context)
 {
     if (!string.IsNullOrWhiteSpace(attribute.Schema))
     {
         entityTypeBuilder.ToTable(attribute.Name, attribute.Schema, fromDataAnnotation: true);
     }
     else if (!string.IsNullOrWhiteSpace(attribute.Name))
     {
         entityTypeBuilder.ToTable(attribute.Name, fromDataAnnotation: true);
     }
 }
示例#2
0
        public virtual void ProcessEntityTypeAdded(
            IConventionEntityTypeBuilder entityTypeBuilder, IConventionContext <IConventionEntityTypeBuilder> context)
        {
            var entityType = entityTypeBuilder.Metadata;

            // Only touch root entities for now (TPH). Revisit for TPT/TPC.
            if (entityType.BaseType == null)
            {
                entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()), entityType.GetSchema());
            }
        }
示例#3
0
        /// <summary>
        ///     Called after the base type of an entity type changes.
        /// </summary>
        /// <param name="entityTypeBuilder"> The builder for the entity type. </param>
        /// <param name="newBaseType"> The new base entity type. </param>
        /// <param name="oldBaseType"> The old base entity type. </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public virtual void ProcessEntityTypeBaseTypeChanged(
            IConventionEntityTypeBuilder entityTypeBuilder,
            IConventionEntityType newBaseType,
            IConventionEntityType oldBaseType,
            IConventionContext <IConventionEntityType> context)
        {
            var entityType = entityTypeBuilder.Metadata;

            if (oldBaseType == null &&
                newBaseType != null)
            {
                entityTypeBuilder.ToTable(null);
            }
            else if (oldBaseType != null &&
                     newBaseType == null &&
                     entityType.ClrType != null &&
                     _sets.ContainsKey(entityType.ClrType))
            {
                entityTypeBuilder.ToTable(_sets[entityType.ClrType].Name);
            }
        }
        /// <summary>
        ///     Called after an entity type is added to the model.
        /// </summary>
        /// <param name="entityTypeBuilder"> The builder for the entity type. </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public virtual void ProcessEntityTypeAdded(
            IConventionEntityTypeBuilder entityTypeBuilder,
            IConventionContext <IConventionEntityTypeBuilder> context)
        {
            var entityType = entityTypeBuilder.Metadata;

            if (entityType.BaseType == null &&
                entityType.ClrType != null &&
                _sets.TryGetValue(entityType.ClrType, out var setName))
            {
                entityTypeBuilder.ToTable(setName);
            }
        }
示例#5
0
        /// <summary>
        ///     Called after an entity type is added to the model.
        /// </summary>
        /// <param name="entityTypeBuilder"> The builder for the entity type. </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public virtual void ProcessEntityTypeAdded(
            IConventionEntityTypeBuilder entityTypeBuilder,
            IConventionContext <IConventionEntityTypeBuilder> context)
        {
            var entityType = entityTypeBuilder.Metadata;

            if (entityType.BaseType == null &&
                entityType.ClrType != null &&
                _sets.ContainsKey(entityType.ClrType))
            {
                entityTypeBuilder.ToTable(_sets[entityType.ClrType].Name);
            }
        }
        /// <summary>
        ///     Called after the base type of an entity type changes.
        /// </summary>
        /// <param name="entityTypeBuilder"> The builder for the entity type. </param>
        /// <param name="newBaseType"> The new base entity type. </param>
        /// <param name="oldBaseType"> The old base entity type. </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public virtual void ProcessEntityTypeBaseTypeChanged(
            IConventionEntityTypeBuilder entityTypeBuilder,
            IConventionEntityType newBaseType,
            IConventionEntityType oldBaseType,
            IConventionContext <IConventionEntityType> context)
        {
            var entityType = entityTypeBuilder.Metadata;

            if (oldBaseType == null &&
                newBaseType != null)
            {
                entityTypeBuilder.HasNoAnnotation(RelationalAnnotationNames.TableName);
            }
            else if (oldBaseType != null &&
                     newBaseType == null &&
                     entityType.ClrType != null &&
                     _sets.TryGetValue(entityType.ClrType, out var setName))
            {
                entityTypeBuilder.ToTable(setName);
            }
        }
 public virtual void ProcessEntityTypeAdded(
     IConventionEntityTypeBuilder entityTypeBuilder, IConventionContext <IConventionEntityTypeBuilder> context)
 => entityTypeBuilder.ToTable(
     RewriteName(entityTypeBuilder.Metadata.GetTableName()),
     entityTypeBuilder.Metadata.GetSchema());
 public void ProcessEntityTypeAdded(
     IConventionEntityTypeBuilder entityTypeBuilder,
     IConventionContext <IConventionEntityTypeBuilder> context)
 => entityTypeBuilder.ToTable(
     ConvertToSnakeCase(entityTypeBuilder.Metadata.GetTableName()),
     entityTypeBuilder.Metadata.GetSchema());