Exemplo n.º 1
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>
        protected override void ValidateSharedKeysCompatibility(
            IReadOnlyList <IEntityType> mappedTypes, string tableName, DiagnosticsLoggers loggers)
        {
            base.ValidateSharedKeysCompatibility(mappedTypes, tableName, loggers);

            var keyMappings = new Dictionary <string, IKey>();

            foreach (var key in mappedTypes.SelectMany(et => et.GetDeclaredKeys()))
            {
                var keyName = key.GetName();

                if (!keyMappings.TryGetValue(keyName, out var duplicateKey))
                {
                    keyMappings[keyName] = key;
                    continue;
                }

                if (key.GetSqlServerIsClustered()
                    != duplicateKey.GetSqlServerIsClustered())
                {
                    throw new InvalidOperationException(
                              SqlServerStrings.DuplicateKeyMismatchedClustering(
                                  key.Properties.Format(),
                                  key.DeclaringEntityType.DisplayName(),
                                  duplicateKey.Properties.Format(),
                                  duplicateKey.DeclaringEntityType.DisplayName(),
                                  tableName,
                                  keyName));
                }
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override void ValidateCompatible(IKey key, IKey duplicateKey, string keyName, string tableName)
        {
            base.ValidateCompatible(key, duplicateKey, keyName, tableName);

            if (key.IsClustered()
                != duplicateKey.IsClustered())
            {
                throw new InvalidOperationException(
                          SqlServerStrings.DuplicateKeyMismatchedClustering(
                              key.Properties.Format(),
                              key.DeclaringEntityType.DisplayName(),
                              duplicateKey.Properties.Format(),
                              duplicateKey.DeclaringEntityType.DisplayName(),
                              tableName,
                              keyName));
            }
        }