/// <summary> /// Gets the foreign key for the given properties that points to a given primary or alternate key. Returns null /// if no foreign key is found. /// </summary> /// <param name="entityType"> The entity type to find the foreign keys on. </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 foreign key, or null if none is defined. </returns> public static IMutableForeignKey FindForeignKey( [NotNull] this IMutableEntityType entityType, [NotNull] IProperty property, [NotNull] IKey principalKey, [NotNull] IEntityType principalEntityType) { Check.NotNull(entityType, nameof(entityType)); return(entityType.FindForeignKey(new[] { property }, principalKey, principalEntityType)); }
/// <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)); }
public static IMutableForeignKey?FindForeignKey( [NotNull] this IMutableEntityType entityType, [NotNull] IReadOnlyProperty property, [NotNull] IReadOnlyKey principalKey, [NotNull] IReadOnlyEntityType principalEntityType) => entityType.FindForeignKey(new[] { property }, principalKey, principalEntityType);