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;

            AreCompatible(principalKey.Properties, dependentProperties, principalEntityType, dependentEntityType, shouldThrow: true);

            if (!principalEntityType.GetKeys().Contains(principalKey))
            {
                throw new ArgumentException(
                          CoreStrings.ForeignKeyReferencedEntityKeyMismatch(
                              Property.Format(principalKey.Properties),
                              principalEntityType));
            }
        }
        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;
        }
Exemple #3
0
        internal Key([NotNull] IReadOnlyList <Property> properties)
        {
            Check.NotEmpty(properties, "properties");
            MetadataHelper.CheckSameEntityType(properties, "properties");

            _properties = properties;
        }
Exemple #4
0
        public Index([NotNull] IReadOnlyList <Property> properties)
        {
            Check.NotEmpty(properties, "properties");
            Check.HasNoNulls(properties, "properties");
            MetadataHelper.CheckSameEntityType(properties, "properties");

            _properties = properties;
        }