public ForeignKey( [NotNull] IReadOnlyList <Property> dependentProperties, [NotNull] Key principalKey, [CanBeNull] EntityType principalEntityType = null) { Check.NotEmpty(dependentProperties, nameof(dependentProperties)); Check.HasNoNulls(dependentProperties, nameof(dependentProperties)); MetadataHelper.CheckSameEntityType(dependentProperties, nameof(dependentProperties)); Check.NotNull(principalKey, nameof(principalKey)); Properties = dependentProperties; var principalProperties = principalKey.Properties; Property.EnsureCompatible(principalProperties, dependentProperties); if (principalEntityType?.GetKeys().Contains(principalKey) == false) { throw new ArgumentException( Strings.ForeignKeyReferencedEntityKeyMismatch( principalKey, principalEntityType)); } _principalKey = principalKey; PrincipalEntityType = principalEntityType ?? _principalKey.EntityType; }
public ForeignKey( [NotNull] IReadOnlyList <Property> dependentProperties, [NotNull] Key principalKey, [NotNull] EntityType dependentEntityType, [NotNull] EntityType principalEntityType) { Check.NotEmpty(dependentProperties, nameof(dependentProperties)); Check.HasNoNulls(dependentProperties, nameof(dependentProperties)); MetadataHelper.CheckSameEntityType(dependentProperties, nameof(dependentProperties)); Check.NotNull(principalKey, nameof(principalKey)); Check.NotNull(principalEntityType, nameof(principalEntityType)); Properties = dependentProperties; PrincipalKey = principalKey; DeclaringEntityType = dependentEntityType; PrincipalEntityType = principalEntityType; Property.EnsureCompatible(principalKey.Properties, dependentProperties, principalEntityType, dependentEntityType); if (!principalEntityType.GetKeys().Contains(principalKey)) { throw new ArgumentException( Strings.ForeignKeyReferencedEntityKeyMismatch( Property.Format(principalKey.Properties), principalEntityType)); } }