Esempio n. 1
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override void ValidateSharedKeysCompatibility(
            IReadOnlyList <IEntityType> mappedTypes, string tableName)
        {
            base.ValidateSharedKeysCompatibility(mappedTypes, tableName);

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

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

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

                if (key.MySql().IsClustered
                    != duplicateKey.MySql().IsClustered)
                {
                    throw new InvalidOperationException(
                              MySqlStrings.DuplicateKeyMismatchedClustering(
                                  Property.Format(key.Properties),
                                  key.DeclaringEntityType.DisplayName(),
                                  Property.Format(duplicateKey.Properties),
                                  duplicateKey.DeclaringEntityType.DisplayName(),
                                  tableName,
                                  keyName));
                }
            }
        }
Esempio n. 2
0
        public virtual void Detects_incompatible_non_clustered_shared_key(bool obsolete)
        {
            var modelBuilder = CreateConventionalModelBuilder();

            modelBuilder.Entity <A>().HasOne <B>().WithOne().IsRequired().HasForeignKey <A>(a => a.Id).HasPrincipalKey <B>(b => b.Id);

            if (obsolete)
            {
#pragma warning disable 618
                modelBuilder.Entity <A>().ToTable("Table")
                .HasKey(a => a.Id).ForMySqlIsClustered();
                modelBuilder.Entity <B>().ToTable("Table")
                .HasKey(b => b.Id).ForMySqlIsClustered(false);
#pragma warning restore 618
            }
            else
            {
                modelBuilder.Entity <A>().ToTable("Table")
                .HasKey(a => a.Id).IsClustered();
                modelBuilder.Entity <B>().ToTable("Table")
                .HasKey(b => b.Id).IsClustered(false);
            }

            VerifyError(
                MySqlStrings.DuplicateKeyMismatchedClustering("{'Id'}", nameof(B), "{'Id'}", nameof(A), "Table", "PK_Table"),
                modelBuilder.Model);
        }