public void PreserveIndexNameOnAdjustIndex() { IMutableIndex origIndex = null; using (var db = GetDbContext(builder => { #if NET builder.Entity <Blog>() .HasIndex(e => e.BlogId, "CustomIndexName") .HasDatabaseName("CustomIndexDbName"); #else builder.Entity <Blog>().HasIndex(e => e.BlogId).HasName("CustomIndexName"); #endif origIndex = builder.Entity <Blog>().Metadata.GetIndexes().First(); builder.Entity <Blog>().IsMultiTenant().AdjustIndex(origIndex); })) { var index = db.Model.FindEntityType(typeof(Blog)).GetIndexes().First(); #if NET Assert.Equal("CustomIndexName", index.Name); Assert.Equal("CustomIndexDbName", index.GetDatabaseName()); #elif NETCOREAPP3_1 Assert.Equal("CustomIndexName", index.GetName()); #elif NETCOREAPP2_1 Assert.Equal("CustomIndexName", index.Relational().Name); #endif } }
/// <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); }
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> /// Sets a value indicating whether the index uses the fill factor. /// </summary> /// <param name="index"> The index. </param> /// <param name="fillFactor"> The value to set. </param> public static void SetFillFactor([NotNull] this IMutableIndex index, int?fillFactor) { if (fillFactor != null && (fillFactor <= 0 || fillFactor > 100)) { throw new ArgumentOutOfRangeException(nameof(fillFactor)); } index.SetOrRemoveAnnotation( SqlServerAnnotationNames.FillFactor, fillFactor); }
public void AdjustIndexOnAdjustIndex() { IMutableIndex origIndex = null; using (var db = GetDbContext(builder => { builder.Entity <Blog>().HasIndex(e => e.BlogId); origIndex = builder.Entity <Blog>().Metadata.GetIndexes().First(); builder.Entity <Blog>().IsMultiTenant().AdjustIndex(origIndex); })) { var index = db.Model.FindEntityType(typeof(Blog)).GetIndexes().First(); Assert.Contains("BlogId", index.Properties.Select(p => p.Name)); Assert.Contains("TenantId", index.Properties.Select(p => p.Name)); } }
public static RelationalIndexAnnotations Relational([NotNull] this IMutableIndex index) => new RelationalIndexAnnotations(Check.NotNull(index, nameof(index)), null);
/// <summary> /// Sets the column NULL sort orders to be used, or <c>null</c> if they have not been specified. /// </summary> /// <remarks> /// https://www.postgresql.org/docs/current/static/indexes-ordering.html /// </remarks> public static void SetNullSortOrder([NotNull] this IMutableIndex index, [CanBeNull] IReadOnlyList <NullSortOrder> nullSortOrder) => index.SetOrRemoveAnnotation(NpgsqlAnnotationNames.IndexNullSortOrder, nullSortOrder);
/// <summary> /// Sets the index filter expression. /// </summary> /// <param name="index"> The index. </param> /// <param name="value"> The value to set. </param> public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] string value) => index.SetAnnotation( RelationalAnnotationNames.Filter, Check.NullButNotEmpty(value, nameof(value)));
/// <summary> /// <para> /// Finds the first <see cref="IMutableIndex" /> that is mapped to the same index in a shared table. /// </para> /// <para> /// This method is typically used by database providers (and other extensions). It is generally /// not used in application code. /// </para> /// </summary> /// <param name="index"> The index. </param> /// <param name="tableName"> The table name. </param> /// <param name="schema"> The schema. </param> /// <returns> The index found, or <see langword="null" /> if none was found.</returns> public static IMutableIndex FindSharedTableRootIndex( [NotNull] this IMutableIndex index, [NotNull] string tableName, [CanBeNull] string schema) => (IMutableIndex)((IIndex)index).FindSharedTableRootIndex(tableName, schema);
/// <summary> /// Sets the column collations to be used, or <c>null</c> if they have not been specified. /// </summary> /// <remarks> /// https://www.postgresql.org/docs/current/static/indexes-collations.html /// </remarks> public static void SetCollation([NotNull] this IMutableIndex index, [CanBeNull] IReadOnlyList <string> collations) => index.SetOrRemoveAnnotation(NpgsqlAnnotationNames.IndexCollation, collations);
/// <summary> /// Gets the Oracle specific metadata for an index. /// </summary> /// <param name="index"> The index to get metadata for. </param> /// <returns> The Oracle specific metadata for the index. </returns> public static OracleIndexAnnotations Oracle([NotNull] this IMutableIndex index) => (OracleIndexAnnotations)Oracle((IIndex)index);
/// <summary> /// Sets a value indicating whether the index is online. /// </summary> /// <param name="index"> The index. </param> /// <param name="createdOnline"> The value to set. </param> public static void SetIsCreatedOnline([NotNull] this IMutableIndex index, bool?createdOnline) => index.SetOrRemoveAnnotation( SqlServerAnnotationNames.CreatedOnline, createdOnline);
/// <summary> /// Sets the index method to be used, or <c>null</c> if it hasn't been specified. /// <c>null</c> selects the default (currently <c>btree</c>). /// </summary> /// <remarks> /// http://www.postgresql.org/docs/current/static/sql-createindex.html /// </remarks> public static void SetMethod([NotNull] this IMutableIndex index, [CanBeNull] string method) => index.SetOrRemoveAnnotation(NpgsqlAnnotationNames.IndexMethod, method);
public IndexBuilder(IMutableIndex index) : base(index) { }
public IndexBuilder(IMutableIndex index) { Builder = ((Index)index).Builder; }
/// <summary> /// <para> /// Finds the first <see cref="IMutableIndex" /> that is mapped to the same index in a shared table-like object. /// </para> /// <para> /// This method is typically used by database providers (and other extensions). It is generally /// not used in application code. /// </para> /// </summary> /// <param name="index"> The index. </param> /// <param name="storeObject"> The identifier of the containing store object. </param> /// <returns> The index found, or <see langword="null" /> if none was found.</returns> public static IMutableIndex FindSharedObjectRootIndex( [NotNull] this IMutableIndex index, StoreObjectIdentifier storeObject) => (IMutableIndex)((IIndex)index).FindSharedObjectRootIndex(storeObject);
public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] string name) => SetDatabaseName(index, name);
/// <summary> /// Sets the name of the index in the database. /// </summary> /// <param name="index"> The index. </param> /// <param name="name"> The value to set. </param> public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNull] string name) { index.SetOrRemoveAnnotation( RelationalAnnotationNames.Name, Check.NullButNotEmpty(name, nameof(name))); }
/// <summary> /// Sets included property names. /// </summary> /// <param name="index">The index.</param> /// <param name="properties">The value to set.</param> public static void SetIncludeProperties([NotNull] this IMutableIndex index, [NotNull] IReadOnlyList <string> properties) => index.SetOrRemoveAnnotation( NpgsqlAnnotationNames.IndexInclude, properties);
/// <summary> /// Sets a value indicating which full text parser to used. /// </summary> /// <param name="value"> The value to set. </param> /// <param name="index"> The index. </param> public static void SetFullTextParser([NotNull] this IMutableIndex index, [CanBeNull] string value) => index.SetOrRemoveAnnotation( MySqlAnnotationNames.FullTextParser, value);
/// <summary> /// Sets a value indicating whether the index is created concurrently. /// </summary> /// <param name="index">The index.</param> /// <param name="createdConcurrently">The value to set.</param> public static void SetIsCreatedConcurrently([NotNull] this IMutableIndex index, bool?createdConcurrently) => index.SetOrRemoveAnnotation(NpgsqlAnnotationNames.CreatedConcurrently, createdConcurrently);
/// <summary> /// Sets a value indicating whether the index is spartial. /// </summary> /// <param name="value"> The value to set. </param> /// <param name="index"> The index. </param> public static void SetIsSpatial([NotNull] this IMutableIndex index, bool?value) => index.SetOrRemoveAnnotation( MySQLAnnotationNames.SpatialIndex, value);
/// <summary> /// Sets the column operators to be used, or <c>null</c> if they have not been specified. /// </summary> /// <remarks> /// https://www.postgresql.org/docs/current/static/indexes-opclass.html /// </remarks> public static void SetOperators([NotNull] this IMutableIndex index, [CanBeNull] IReadOnlyList <string> operators) => index.SetOrRemoveAnnotation(NpgsqlAnnotationNames.IndexOperators, operators);
public static RelationalIndexAnnotations SqlCe([NotNull] this IMutableIndex index) => (RelationalIndexAnnotations)SqlCe((IIndex)index);
/// <summary> /// Sets prefix lengths for the index. /// </summary> /// <param name="values"> The prefix lengths to set. /// A value of `0` indicates, that the full length should be used for that column. </param> /// <param name="index"> The index. </param> public static void SetPrefixLength([NotNull] this IMutableIndex index, int[] values) => index.SetOrRemoveAnnotation( MySqlAnnotationNames.IndexPrefixLength, values);
public static RelationalIndexAnnotations MyCat([NotNull] this IMutableIndex index) => (MyCatIndexAnnotations)MyCat((IIndex)index);
/// <summary> /// Sets a value indicating whether the index is full text. /// </summary> /// <param name="value"> The value to set. </param> /// <param name="index"> The index. </param> public static void SetIsFullText([NotNull] this IMutableIndex index, bool?value) => index.SetOrRemoveAnnotation( MySQLAnnotationNames.FullTextIndex, value);
/// <summary> /// Sets a value indicating whether the index is clustered. /// </summary> /// <param name="value"> The value to set. </param> /// <param name="index"> The index. </param> public static void SetIsClustered([NotNull] this IMutableIndex index, bool?value) => index.SetOrRemoveAnnotation( SqlServerAnnotationNames.Clustered, value);
/// <summary> /// Gets the SQL Server specific metadata for an index. /// </summary> /// <param name="index"> The index to get metadata for. </param> /// <returns> The SQL Server specific metadata for the index. </returns> public static MySqlIndexAnnotations MySql([NotNull] this IMutableIndex index) => (MySqlIndexAnnotations)MySql((IIndex)index);
public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] string name) => index.Name = Check.NullButNotEmpty(name, nameof(name));