Ejemplo n.º 1
0
        /// <summary>
        ///     Sets the <see cref="IProperty" /> that will be used for storing a discriminator value.
        /// </summary>
        /// <param name="entityType"> The entity type to set the discriminator property for. </param>
        /// <param name="property"> The property to set. </param>
        public static void SetDiscriminatorProperty([NotNull] this IMutableEntityType entityType, [CanBeNull] IProperty property)
        {
            CheckDiscriminatorProperty(entityType, property);

            var oldDiscriminatorType = entityType.GetDiscriminatorProperty()?.ClrType;

            if (property == null ||
                property.ClrType != oldDiscriminatorType)
            {
                foreach (var derivedType in entityType.GetDerivedTypesInclusive())
                {
                    derivedType.RemoveDiscriminatorValue();
                }
            }

            entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.DiscriminatorProperty, property?.Name);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Returns all types in hierarchy of the given <see cref="IMutableEntityType" />.
 /// </summary>
 /// <param name="entityType"> The entity type. </param>
 /// <returns> All types in the hierarchy. </returns>
 public static IEnumerable <IMutableEntityType> GetTypesInHierarchy([NotNull] this IMutableEntityType entityType)
 => entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()).Cast <IMutableEntityType>();