コード例 #1
0
 protected override void Apply(IMutableEntityType entityType)
 {
     foreach (var property in entityType.GetProperties().Where(x => x.ClrType == typeof(decimal)))
     {
         property.Relational().ColumnType = $"DECIMAL({_precision},{_scale})";
     }
 }
コード例 #2
0
 protected abstract void Apply(IMutableEntityType entityType);
コード例 #3
0
 /// <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)));
コード例 #4
0
 /// <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);
コード例 #5
0
 /// <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);
コード例 #6
0
 /// <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();
コード例 #7
0
 /// <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);
コード例 #8
0
 /// <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();
コード例 #9
0
 /// <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>();
コード例 #10
0
 /// <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>();
コード例 #11
0
 /// <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>();
コード例 #12
0
 /// <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>();
コード例 #13
0
 private static void testForeignKey(IMutableEntityType entity, int foreignKeysCount)
 {
     Assert.AreEqual(foreignKeysCount, entity.GetForeignKeys().Count());
 }
コード例 #14
0
 public TableBuilder(string name, string?schema, IMutableEntityType entityType)
 {
     EntityType = entityType;
 }
コード例 #15
0
 /// <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)));
コード例 #16
0
 private static bool ShouldFilterSoftDelete <TUserId>(IMutableEntityType entityType)
 {
     return(typeof(ISoftDelete <TUserId>).IsAssignableFrom(entityType.ClrType));
 }
コード例 #17
0
 /// <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);
コード例 #18
0
 /// <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);
コード例 #19
0
 /// <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 });
コード例 #20
0
 /// <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)));
コード例 #21
0
 /// <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();
コード例 #22
0
 public static RelationalEntityTypeAnnotations MySql([NotNull] this IMutableEntityType entityType)
 => (RelationalEntityTypeAnnotations)MySql((IEntityType)entityType);
コード例 #23
0
 /// <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();
コード例 #24
0
 /// <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();
コード例 #25
0
 /// <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());
コード例 #26
0
 /// <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();
コード例 #27
0
 /// <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();
コード例 #28
0
 /// <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);
コード例 #29
0
 /// <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();
コード例 #30
0
        /// <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 }));
        }
コード例 #31
0
 /// <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 });
コード例 #32
0
 public TemporalTableBuilder(IMutableEntityType entityType)
 {
     _entityType = entityType;
 }