/// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 protected virtual void SetDefaultDiscriminatorValues(
     [NotNull] IEnumerable <IConventionEntityType> entityTypes, [NotNull] IConventionDiscriminatorBuilder discriminator)
 {
     foreach (var entityType in entityTypes)
     {
         discriminator.HasValue(entityType, entityType.ShortName());
     }
 }
 private static void SetDefaultDiscriminatorValues(
     IReadOnlyList <EntityType> entityTypes, IConventionDiscriminatorBuilder discriminator)
 {
     foreach (var entityType in entityTypes)
     {
         discriminator.HasValue(entityType, entityType.ShortName());
     }
 }
Exemplo n.º 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 override void ProcessEntityTypeBaseTypeChanged(
            IConventionEntityTypeBuilder entityTypeBuilder,
            IConventionEntityType newBaseType,
            IConventionEntityType oldBaseType,
            IConventionContext <IConventionEntityType> context)
        {
            if (entityTypeBuilder.Metadata.BaseType != newBaseType)
            {
                return;
            }

            IConventionDiscriminatorBuilder discriminator = null;
            var entityType = entityTypeBuilder.Metadata;

            if (newBaseType == null)
            {
                if (entityType.IsDocumentRoot())
                {
                    discriminator = entityTypeBuilder.HasDiscriminator(typeof(string));
                }
            }
            else
            {
                discriminator = newBaseType.Builder?.HasDiscriminator(typeof(string));

                if (newBaseType.BaseType == null)
                {
                    discriminator?.HasValue(newBaseType, newBaseType.ShortName());
                }
            }

            if (discriminator != null)
            {
                discriminator.HasValue(entityTypeBuilder.Metadata, entityTypeBuilder.Metadata.ShortName());
                SetDefaultDiscriminatorValues(entityType.GetDerivedTypes(), discriminator);
            }
        }