public virtual void Passes_for_compatible_duplicate_index_names_within_hierarchy() { var modelBuilder = CreateConventionalModelBuilder(); IMutableIndex index1 = null; IMutableIndex index2 = null; modelBuilder.Entity <Animal>(); modelBuilder.Entity <Cat>( et => { et.Property(c => c.Breed).HasColumnName("Breed"); index1 = et.HasIndex(c => c.Breed).HasName("IX_Animal_Breed").Metadata; }); modelBuilder.Entity <Dog>( et => { et.Property(c => c.Breed).HasColumnName("Breed"); index2 = et.HasIndex(c => c.Breed).HasName("IX_Animal_Breed").Metadata; }); Validate(modelBuilder.Model); Assert.NotSame(index1, index2); Assert.Equal(index1.GetName(), index2.GetName()); }
/// <summary> /// Adds TenantId to the index. /// </summary> /// <param name="index">The index to adjust for TenantId.</param> /// <returns>The MultiTenantEntityTypeBuilder instance.</returns> public MultiTenantEntityTypeBuilder AdjustIndex(IMutableIndex index) { // Set the new unique index with TenantId preserving name and database name IndexBuilder indexBuilder = null; #if NET Builder.Metadata.RemoveIndex(index); if (index.Name != null) { indexBuilder = Builder .HasIndex(index.Properties.Select(p => p.Name).Append("TenantId").ToArray(), index.Name) .HasDatabaseName(index.GetDatabaseName()); } else { indexBuilder = Builder.HasIndex(index.Properties.Select(p => p.Name).Append("TenantId").ToArray()) .HasDatabaseName(index.GetDatabaseName()); } #elif NETSTANDARD2_1 Builder.Metadata.RemoveIndex(index.Properties); indexBuilder = Builder.HasIndex(index.Properties.Select(p => p.Name).Append("TenantId").ToArray()) .HasName(index.GetName()); #elif NETSTANDARD2_0 Builder.Metadata.RemoveIndex(index.Properties); indexBuilder = Builder.HasIndex(index.Properties.Select(p => p.Name).Append("TenantId").ToArray()) .HasName(index.Relational().Name); #endif if (index.IsUnique) { indexBuilder.IsUnique(); } return(this); }