/// <summary> /// Adds a new relationship to this entity type. /// </summary> /// <param name="entityType"> The entity type to add the foreign key to. </param> /// <param name="property"> The property 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 newly created foreign key. </returns> public static IMutableForeignKey AddForeignKey( [NotNull] this IMutableEntityType entityType, [NotNull] IMutableProperty property, [NotNull] IMutableKey principalKey, [NotNull] IMutableEntityType principalEntityType) { Check.NotNull(entityType, nameof(entityType)); return(entityType.AddForeignKey(new[] { property }, principalKey, principalEntityType)); }
protected IMutableForeignKey CreateForeignKey( IMutableEntityType dependEntityType, IReadOnlyList <IMutableProperty> dependentProperties, IMutableKey principalKey) { var foreignKey = dependEntityType.AddForeignKey(dependentProperties, principalKey, principalKey.DeclaringEntityType); foreignKey.IsUnique = true; return(foreignKey); }
/// <summary> /// Gets an existing relationship, or creates a new one if one is not already defined. /// </summary> /// <param name="entityType"> The entity type to get or add the foreign key to. </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 existing or newly created foreign key. </returns> public static IMutableForeignKey GetOrAddForeignKey( [NotNull] this IMutableEntityType entityType, [NotNull] IReadOnlyList <IMutableProperty> properties, [NotNull] IMutableKey principalKey, [NotNull] IMutableEntityType principalEntityType) { Check.NotNull(entityType, nameof(entityType)); return(entityType.FindForeignKey(properties, principalKey, principalEntityType) ?? entityType.AddForeignKey(properties, principalKey, principalEntityType)); }
protected IMutableForeignKey CreateForeignKey(IMutableKey dependentKey, IMutableKey principalKey) => CreateForeignKey(dependentKey.DeclaringEntityType, dependentKey.Properties, principalKey);
/// <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);
IMutableForeignKey IMutableEntityType.AddForeignKey( IReadOnlyList <IMutableProperty> properties, IMutableKey principalKey, IMutableEntityType principalEntityType) => AddForeignKey(properties.Cast <Property>().ToList(), (Key)principalKey, (EntityType)principalEntityType);
/// <summary> /// Gets the Oracle specific metadata for a key. /// </summary> /// <param name="key"> The key to get metadata for. </param> /// <returns> The Oracle specific metadata for the key. </returns> public static OracleKeyAnnotations Oracle([NotNull] this IMutableKey key) => (OracleKeyAnnotations)Oracle((IKey)key);
public static RelationalKeyAnnotations MyCat([NotNull] this IMutableKey key) => (RelationalKeyAnnotations)MyCat((IKey)key);
/// <summary> /// Gets the relational database specific metadata for a key. /// </summary> /// <param name="key"> The key to get metadata for. </param> /// <returns> The relational database specific metadata for the key. </returns> public static RelationalKeyAnnotations Relational([NotNull] this IMutableKey key) => (RelationalKeyAnnotations)Relational((IKey)key);
public static SqlServerKeyAnnotations SqlServer([NotNull] this IMutableKey key) => (SqlServerKeyAnnotations)SqlServer((IKey)key);
/// <summary> /// Sets prefix lengths for the key. /// </summary> /// <param name="values"> The prefix lengths to set. /// A value of `0` indicates, that the full length should be used for that column. </param> /// <param name="key"> The key. </param> public static void SetPrefixLength([NotNull] this IMutableKey key, int[] values) => key.SetOrRemoveAnnotation( MySqlAnnotationNames.IndexPrefixLength, values);
public static RelationalKeyAnnotations MySQL(this IMutableKey key) => (RelationalKeyAnnotations)MySQL((IKey)key);
/// <summary> /// Gets the Jet specific metadata for a key. /// </summary> /// <param name="key"> The key to get metadata for. </param> /// <returns> The Jet specific metadata for the key. </returns> public static JetKeyAnnotations Jet([NotNull] this IMutableKey key) => (JetKeyAnnotations)Jet((IKey)key);
public static IEnumerable <IMutableForeignKey> GetReferencingForeignKeys([NotNull] this IMutableKey key) => ((IReadOnlyKey)key).GetReferencingForeignKeys().Cast <IMutableForeignKey>();
public static RelationalKeyAnnotations SqlCe([NotNull] this IMutableKey key) => (RelationalKeyAnnotations)SqlCe((IKey)key);
/// <summary> /// Sets a value indicating whether the key is clustered. /// </summary> /// <param name="key"> The key. </param> /// <param name="clustered"> The value to set. </param> public static void SetIsClustered([NotNull] this IMutableKey key, bool?clustered) => key.SetOrRemoveAnnotation(SqlServerAnnotationNames.Clustered, clustered);
public static AS400KeyAnnotations AS400([NotNull] this IMutableKey key) => (AS400KeyAnnotations)(IKey)key.AS400();
/// <summary> /// <para> /// Finds the first <see cref="IMutableKey" /> that is mapped to the same constraint in a shared table-like object. /// </para> /// <para> /// This method is typically used by database providers (and other extensions). It is generally /// not used in application code. /// </para> /// </summary> /// <param name="key"> The key. </param> /// <param name="storeObject"> The identifier of the containing store object. </param> /// <returns> The key found, or <see langword="null" /> if none was found.</returns> public static IMutableKey FindSharedObjectRootKey( [NotNull] this IMutableKey key, StoreObjectIdentifier storeObject) => (IMutableKey)((IKey)key).FindSharedObjectRootKey(storeObject);
public KeyBuilder(IMutableKey key) : base(key) { }
public KeyBuilder([NotNull] IMutableKey key) : base(key) { }
public static FirebirdSqlKeyAnnotations FirebirdSql([NotNull] this IMutableKey key) => (FirebirdSqlKeyAnnotations)FirebirdSql((IKey)key);
public KeyBuilder([NotNull] IMutableKey key) { Check.NotNull(key, nameof(key)); Builder = ((Key)key).Builder; }
public static RelationalKeyAnnotations Relational([NotNull] this IMutableKey key) => new RelationalKeyAnnotations(Check.NotNull(key, nameof(key)), null);
/// <summary> /// Gets an existing relationship, or creates a new one if one is not already defined. /// </summary> /// <param name="entityType"> The entity type to get or add the foreign key to. </param> /// <param name="property"> The property 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 existing or newly created foreign key. </returns> public static IMutableForeignKey GetOrAddForeignKey( [NotNull] this IMutableEntityType entityType, [NotNull] IMutableProperty property, [NotNull] IMutableKey principalKey, [NotNull] IMutableEntityType principalEntityType) => entityType.GetOrAddForeignKey(new[] { property }, principalKey, principalEntityType);
/// <summary> /// <para> /// Finds the first <see cref="IMutableKey" /> that is mapped to the same constraint in a shared table. /// </para> /// <para> /// This method is typically used by database providers (and other extensions). It is generally /// not used in application code. /// </para> /// </summary> /// <param name="key"> The key. </param> /// <param name="tableName"> The table name. </param> /// <param name="schema"> The schema. </param> /// <returns> The key found, or <see langword="null" /> if none was found.</returns> public static IMutableKey FindSharedTableRootKey( [NotNull] this IMutableKey key, [NotNull] string tableName, [CanBeNull] string schema) => (IMutableKey)((IKey)key).FindSharedTableRootKey(tableName, schema);
/// <summary> /// Sets the key constraint name for this key. /// </summary> /// <param name="key"> The key. </param> /// <param name="name"> The value to set. </param> public static void SetName([NotNull] this IMutableKey key, [CanBeNull] string name) => key.SetOrRemoveAnnotation( RelationalAnnotationNames.Name, Check.NullButNotEmpty(name, nameof(name)));
/// <summary> /// Gets all foreign keys that target a given primary or alternate key. /// </summary> /// <param name="key"> The key to find the foreign keys for. </param> /// <returns> The foreign keys that reference the given key. </returns> public static IEnumerable <IMutableForeignKey> FindReferencingForeignKeys([NotNull] this IMutableKey key) => ((IKey)key).FindReferencingForeignKeys().Cast <IMutableForeignKey>();
/// <summary> /// Gets the SQL Server specific metadata for a key. /// </summary> /// <param name="key"> The key to get metadata for. </param> /// <returns> The SQL Server specific metadata for the key. </returns> public static MySqlKeyAnnotations MySql([NotNull] this IMutableKey key) => (MySqlKeyAnnotations)MySql((IKey)key);
public static FbKeyAnnotations Firebird(this IMutableKey key) => (FbKeyAnnotations)Firebird((IKey)key);