protected override void Apply(IMutableEntityType entityType) { foreach (var property in entityType.GetProperties().Where(x => x.ClrType == typeof(decimal))) { property.Relational().ColumnType = $"DECIMAL({_precision},{_scale})"; } }
protected abstract void Apply(IMutableEntityType entityType);
/// <summary> /// Gets a navigation property on the given entity type. Does not return navigation properties defined on a base type. /// Returns <c>null</c> if no navigation property is found. /// </summary> /// <param name="entityType"> The entity type to find the navigation property on. </param> /// <param name="name"> The name of the navigation property on the entity class. </param> /// <returns> The navigation property, or <c>null</c> if none is found. </returns> public static IMutableNavigation FindDeclaredNavigation([NotNull] this IMutableEntityType entityType, [NotNull] string name) => ((EntityType)entityType).FindDeclaredNavigation(Check.NotNull(name, nameof(name)));
/// <summary> /// Gets a navigation property on the given entity type. Returns <c>null</c> if no navigation property is found. /// </summary> /// <param name="entityType"> The entity type to find the navigation property on. </param> /// <param name="name"> The name of the navigation property on the entity class. </param> /// <returns> The navigation property, or <c>null</c> if none is found. </returns> public static IMutableNavigation FindNavigation([NotNull] this IMutableEntityType entityType, [NotNull] string name) => ((EntityType)entityType).FindNavigation(name);
/// <summary> /// Removes a foreign key from this entity type. /// </summary> /// <param name="entityType"> The entity type to remove the foreign key from. </param> /// <param name="properties"> The properties that the foreign key is defined on. </param> /// <param name="principalKey"> The primary or alternate key that is referenced. </param> /// <param name="principalEntityType"> /// The entity type that the relationship targets. This may be different from the type that <paramref name="principalKey" /> /// is defined on when the relationship targets a derived type in an inheritance hierarchy (since the key is defined on the /// base type of the hierarchy). /// </param> /// <returns> The foreign key that was removed. </returns> public static IMutableForeignKey RemoveForeignKey( [NotNull] this IMutableEntityType entityType, [NotNull] IReadOnlyList <IMutableProperty> properties, [NotNull] IMutableKey principalKey, [NotNull] IMutableEntityType principalEntityType) => ((EntityType)entityType).RemoveForeignKey(properties, principalKey, principalEntityType);
/// <summary> /// Gets all foreign keys that target a given entity type (i.e. foreign keys where the given entity type /// is the principal). /// </summary> /// <param name="entityType"> The entity type to find the foreign keys for. </param> /// <returns> The foreign keys that reference the given entity type. </returns> public static IEnumerable <IMutableForeignKey> GetDeclaredReferencingForeignKeys([NotNull] this IMutableEntityType entityType) => ((EntityType)entityType).GetDeclaredReferencingForeignKeys();
/// <summary> /// Gets the foreign keys declared on the given <see cref="IConventionEntityType" /> using the given properties. /// </summary> /// <param name="entityType"> The entity type. </param> /// <param name="properties"> The properties to find the foreign keys on. </param> /// <returns> Declared foreign keys. </returns> public static IEnumerable <IMutableForeignKey> FindDeclaredForeignKeys( [NotNull] this IMutableEntityType entityType, [NotNull] IReadOnlyList <IProperty> properties) => ((EntityType)entityType).FindDeclaredForeignKeys(properties);
/// <summary> /// <para> /// Gets all foreign keys declared on the types derived from the given <see cref="IMutableEntityType" />. /// </para> /// <para> /// This method does not return foreign keys declared on the given entity type itself. /// Use <see cref="IMutableEntityType.GetForeignKeys" /> to return foreign keys declared on this /// and base entity typed types. /// </para> /// </summary> /// <param name="entityType"> The entity type. </param> /// <returns> Derived foreign keys. </returns> public static IEnumerable <IMutableForeignKey> GetDerivedForeignKeys([NotNull] this IMutableEntityType entityType) => ((EntityType)entityType).GetDerivedForeignKeys();
/// <summary> /// <para> /// Gets all navigation properties declared on the given <see cref="IMutableEntityType" />. /// </para> /// <para> /// This method does not return navigation properties declared on derived types. /// It is useful when iterating over all entity types to avoid processing the same navigation property more than once. /// Use <see cref="GetNavigations" /> to also return navigation properties declared on derived types. /// </para> /// </summary> /// <param name="entityType"> The entity type. </param> /// <returns> Declared navigation properties. </returns> public static IEnumerable <IMutableNavigation> GetDeclaredNavigations([NotNull] this IMutableEntityType entityType) => ((IEntityType)entityType).GetDeclaredNavigations().Cast <IMutableNavigation>();
/// <summary> /// <para> /// Gets all non-navigation properties declared on the given <see cref="IMutableEntityType" />. /// </para> /// <para> /// This method does not return properties declared on derived types. /// It is useful when iterating over all entity types to avoid processing the same property more than once. /// Use <see cref="IMutableEntityType.GetProperties" /> to also return properties declared on derived types. /// </para> /// </summary> /// <param name="entityType"> The entity type. </param> /// <returns> Declared non-navigation properties. </returns> public static IEnumerable <IMutableProperty> GetDeclaredProperties([NotNull] this IMutableEntityType entityType) => ((IEntityType)entityType).GetDeclaredProperties().Cast <IMutableProperty>();
/// <summary> /// <para> /// Gets all foreign keys declared on the given <see cref="IMutableEntityType" />. /// </para> /// <para> /// This method does not return foreign keys declared on derived types. /// It is useful when iterating over all entity types to avoid processing the same foreign key more than once. /// Use <see cref="IMutableEntityType.GetForeignKeys" /> to also return foreign keys declared on derived types. /// </para> /// </summary> /// <param name="entityType"> The entity type. </param> /// <returns> Declared foreign keys. </returns> public static IEnumerable <IMutableForeignKey> GetDeclaredForeignKeys([NotNull] this IMutableEntityType entityType) => ((IEntityType)entityType).GetDeclaredForeignKeys().Cast <IMutableForeignKey>();
/// <summary> /// Returns all derived types of the given <see cref="IMutableEntityType" />, including the type itself. /// </summary> /// <param name="entityType"> The entity type. </param> /// <returns> Derived types. </returns> public static IEnumerable <IMutableEntityType> GetDerivedTypesInclusive([NotNull] this IMutableEntityType entityType) => ((IEntityType)entityType).GetDerivedTypesInclusive().Cast <IMutableEntityType>();
private static void testForeignKey(IMutableEntityType entity, int foreignKeysCount) { Assert.AreEqual(foreignKeysCount, entity.GetForeignKeys().Count()); }
public TableBuilder(string name, string?schema, IMutableEntityType entityType) { EntityType = entityType; }
/// <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> public static void SetDbSetName(this IMutableEntityType entityType, string?value) => entityType.SetAnnotation( ScaffoldingAnnotationNames.DbSetName, Check.NullButNotEmpty(value, nameof(value)));
private static bool ShouldFilterSoftDelete <TUserId>(IMutableEntityType entityType) { return(typeof(ISoftDelete <TUserId>).IsAssignableFrom(entityType.ClrType)); }
/// <summary> /// Removes a primary or alternate key from this entity type. /// </summary> /// <param name="entityType"> The entity type to add remove the key from. </param> /// <param name="properties"> The properties that make up the key. </param> /// <returns> The key that was removed. </returns> public static IMutableKey RemoveKey( [NotNull] this IMutableEntityType entityType, [NotNull] IReadOnlyList <IMutableProperty> properties) => ((EntityType)entityType).RemoveKey(properties);
/// <summary> /// Gets the Jet specific metadata for an entity. /// </summary> /// <param name="entityType"> The entity to get metadata for. </param> /// <returns> The Jet specific metadata for the entity. </returns> public static JetEntityTypeAnnotations Jet([NotNull] this IMutableEntityType entityType) => (JetEntityTypeAnnotations)Jet((IEntityType)entityType);
/// <summary> /// Gets the foreign keys defined on the given property. Only foreign keys that are defined on exactly the specified /// property are returned. Composite foreign keys that include the specified property are not returned. /// </summary> /// <param name="entityType"> The entity type to find the foreign keys on. </param> /// <param name="property"> The property to find the foreign keys on. </param> /// <returns> The foreign keys. </returns> public static IEnumerable <IMutableForeignKey> FindForeignKeys( [NotNull] this IMutableEntityType entityType, [NotNull] IProperty property) => entityType.FindForeignKeys(new[] { property });
/// <summary> /// Sets the name of the container to which the entity type is mapped. /// </summary> /// <param name="entityType">The entity type to set the container name for.</param> /// <param name="name">The name to set.</param> public static void SetContainer(this IMutableEntityType entityType, string?name) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.ContainerName, Check.NullButNotEmpty(name, nameof(name)));
/// <summary> /// Gets the root base type for a given entity type. /// </summary> /// <param name="entityType"> The type to find the root of. </param> /// <returns> /// The root base type. If the given entity type is not a derived type, then the same entity type is returned. /// </returns> public static IMutableEntityType GetRootType([NotNull] this IMutableEntityType entityType) => (IMutableEntityType)((IEntityType)entityType).GetRootType();
public static RelationalEntityTypeAnnotations MySql([NotNull] this IMutableEntityType entityType) => (RelationalEntityTypeAnnotations)MySql((IEntityType)entityType);
/// <summary> /// Returns the relationship to the owner if this is an owned type or <c>null</c> otherwise. /// </summary> /// <param name="entityType"> The entity type to find the foreign keys on. </param> /// <returns> The relationship to the owner if this is an owned type or <c>null</c> otherwise. </returns> public static IMutableForeignKey FindOwnership([NotNull] this IMutableEntityType entityType) => ((EntityType)entityType).FindOwnership();
/// <summary> /// <para> /// Gets all service properties declared on the given <see cref="IMutableEntityType" />. /// </para> /// <para> /// This method does not return properties declared on base types. /// It is useful when iterating over all entity types to avoid processing the same property more than once. /// Use <see cref="IMutableEntityType.GetServiceProperties" /> to also return properties declared on base types. /// </para> /// </summary> /// <param name="entityType"> The entity type. </param> /// <returns> Declared service properties. </returns> public static IEnumerable <IMutableServiceProperty> GetDeclaredServiceProperties([NotNull] this IMutableEntityType entityType) => ((EntityType)entityType).GetDeclaredServiceProperties();
/// <summary> /// Gets a navigation property on the given entity type. Returns <c>null</c> if no navigation property is found. /// </summary> /// <param name="entityType"> The entity type to find the navigation property on. </param> /// <param name="memberInfo"> The navigation property on the entity class. </param> /// <returns> The navigation property, or <c>null</c> if none is found. </returns> public static IMutableNavigation FindNavigation( [NotNull] this IMutableEntityType entityType, [NotNull] MemberInfo memberInfo) => Check.NotNull(entityType, nameof(entityType)) .FindNavigation(Check.NotNull(memberInfo, nameof(memberInfo)).GetSimpleMemberName());
/// <summary> /// <para> /// Gets all indexes declared on the given <see cref="IMutableEntityType" />. /// </para> /// <para> /// This method does not return indexes declared on base types. /// It is useful when iterating over all entity types to avoid processing the same index more than once. /// Use <see cref="IMutableEntityType.GetForeignKeys" /> to also return indexes declared on base types. /// </para> /// </summary> /// <param name="entityType"> The entity type. </param> /// <returns> Declared indexes. </returns> public static IEnumerable <IMutableIndex> GetDeclaredIndexes([NotNull] this IMutableEntityType entityType) => ((EntityType)entityType).GetDeclaredIndexes();
/// <summary> /// Gets all types in the model that derive from a given entity type. /// </summary> /// <param name="entityType"> The base type to find types that derive from. </param> /// <returns> The derived types. </returns> public static IEnumerable <IMutableEntityType> GetDerivedTypes([NotNull] this IMutableEntityType entityType) => ((EntityType)entityType).GetDerivedTypes();
/// <summary> /// Removes a property from this entity type. /// </summary> /// <param name="entityType"> The entity type. </param> /// <param name="name"> The name of the property to remove. </param> /// <returns> The property that was removed. </returns> public static IMutableProperty RemoveProperty([NotNull] this IMutableEntityType entityType, [NotNull] string name) => ((EntityType)entityType).RemoveProperty(name);
/// <summary> /// Returns the defining navigation if one exists or <c>null</c> otherwise. /// </summary> /// <param name="entityType"> The entity type to find the defining navigation for. </param> /// <returns> The defining navigation if one exists or <c>null</c> otherwise. </returns> public static IMutableNavigation FindDefiningNavigation([NotNull] this IMutableEntityType entityType) => (IMutableNavigation)((IEntityType)entityType).FindDefiningNavigation();
/// <summary> /// Gets the primary or alternate key that is defined on the given property. Returns <c>null</c> if no key is defined /// for the given property. /// </summary> /// <param name="entityType"> The entity type to find the key on. </param> /// <param name="property"> The property that the key is defined on. </param> /// <returns> The key, or null if none is defined. </returns> public static IMutableKey FindKey([NotNull] this IMutableEntityType entityType, [NotNull] IProperty property) { Check.NotNull(entityType, nameof(entityType)); return(entityType.FindKey(new[] { property })); }
/// <summary> /// Adds a new alternate key to this entity type. /// </summary> /// <param name="entityType"> The entity type to add the alternate key to. </param> /// <param name="property"> The property to use as an alternate key. </param> /// <returns> The newly created key. </returns> public static IMutableKey AddKey( [NotNull] this IMutableEntityType entityType, [NotNull] IMutableProperty property) => Check.NotNull(entityType, nameof(entityType)).AddKey(new[] { property });
public TemporalTableBuilder(IMutableEntityType entityType) { _entityType = entityType; }