Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ private static readonly MethodInfo TemporalPropertyHasColumnNameMethodInfo
= typeof(TemporalPeriodPropertyBuilder).GetRuntimeMethod(
nameof(TemporalPeriodPropertyBuilder.HasColumnName), [typeof(string)])!;

private static readonly MethodInfo ModelHasFullTextCatalogMethodInfo
= typeof(SqlServerModelBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerModelBuilderExtensions.HasFullTextCatalog), [typeof(ModelBuilder), typeof(string)])!;

private static readonly MethodInfo FullTextCatalogIsDefaultMethodInfo
= typeof(SqlServerFullTextCatalogBuilder).GetRuntimeMethod(
nameof(SqlServerFullTextCatalogBuilder.IsDefault), [typeof(bool)])!;

private static readonly MethodInfo FullTextCatalogIsAccentSensitiveMethodInfo
= typeof(SqlServerFullTextCatalogBuilder).GetRuntimeMethod(
nameof(SqlServerFullTextCatalogBuilder.IsAccentSensitive), [typeof(bool)])!;

private static readonly MethodInfo IndexHasFullTextKeyIndexMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFullTextKeyIndex), [typeof(IndexBuilder), typeof(string)])!;

private static readonly MethodInfo IndexHasFullTextCatalogMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFullTextCatalog), [typeof(IndexBuilder), typeof(string)])!;

private static readonly MethodInfo IndexHasFullTextChangeTrackingMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFullTextChangeTracking), [typeof(IndexBuilder), typeof(FullTextChangeTracking)])!;

private static readonly MethodInfo IndexHasFullTextLanguageMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFullTextLanguage), [typeof(IndexBuilder), typeof(string), typeof(string)])!;

#endregion MethodInfos

/// <summary>
Expand Down Expand Up @@ -192,6 +220,28 @@ public override IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
SqlServerAnnotationNames.PerformanceLevelSql, ModelHasPerformanceLevelSqlMethodInfo,
fragments);

if (annotations.Remove(SqlServerAnnotationNames.FullTextCatalogs, out var catalogsAnnotation)
&& catalogsAnnotation.Value is Dictionary<string, SqlServerFullTextCatalog> catalogs)
{
foreach (var catalog in catalogs.Values.OrderBy(c => c.Name))
{
var catalogCall = new MethodCallCodeFragment(ModelHasFullTextCatalogMethodInfo, catalog.Name);

if (catalog.IsDefault)
{
catalogCall = catalogCall.Chain(new MethodCallCodeFragment(FullTextCatalogIsDefaultMethodInfo));
}

if (!catalog.IsAccentSensitive)
{
catalogCall = catalogCall.Chain(
new MethodCallCodeFragment(FullTextCatalogIsAccentSensitiveMethodInfo, false));
}

fragments.Add(catalogCall);
}
}

return fragments;
}

Expand Down Expand Up @@ -419,6 +469,30 @@ protected override bool IsHandledByConvention(IProperty property, IAnnotation an
_ => null
};

/// <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>
public override IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
IIndex index,
IDictionary<string, IAnnotation> annotations)
{
var fragments = new List<MethodCallCodeFragment>(base.GenerateFluentApiCalls(index, annotations));

if (annotations.Remove(SqlServerAnnotationNames.FullTextLanguages, out var languagesAnnotation)
&& languagesAnnotation.Value is Dictionary<string, string> languages)
{
foreach (var (propertyName, language) in languages.OrderBy(l => l.Key))
{
fragments.Add(new MethodCallCodeFragment(IndexHasFullTextLanguageMethodInfo, propertyName, language));
}
}

return fragments;
}

/// <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
Expand All @@ -432,10 +506,21 @@ protected override bool IsHandledByConvention(IProperty property, IAnnotation an
? new MethodCallCodeFragment(IndexIsClusteredMethodInfo, false)
: new MethodCallCodeFragment(IndexIsClusteredMethodInfo),

SqlServerAnnotationNames.Include => new MethodCallCodeFragment(IndexIncludePropertiesMethodInfo, annotation.Value),
SqlServerAnnotationNames.FillFactor => new MethodCallCodeFragment(IndexHasFillFactorMethodInfo, annotation.Value),
SqlServerAnnotationNames.SortInTempDb => new MethodCallCodeFragment(IndexSortInTempDbMethodInfo, annotation.Value),
SqlServerAnnotationNames.DataCompression => new MethodCallCodeFragment(IndexUseDataCompressionMethodInfo, annotation.Value),
SqlServerAnnotationNames.Include
=> new MethodCallCodeFragment(IndexIncludePropertiesMethodInfo, annotation.Value),
SqlServerAnnotationNames.FillFactor
=> new MethodCallCodeFragment(IndexHasFillFactorMethodInfo, annotation.Value),
SqlServerAnnotationNames.SortInTempDb
=> new MethodCallCodeFragment(IndexSortInTempDbMethodInfo, annotation.Value),
SqlServerAnnotationNames.DataCompression
=> new MethodCallCodeFragment(IndexUseDataCompressionMethodInfo, annotation.Value),

SqlServerAnnotationNames.FullTextIndex
=> new MethodCallCodeFragment(IndexHasFullTextKeyIndexMethodInfo, annotation.Value),
SqlServerAnnotationNames.FullTextCatalog
=> new MethodCallCodeFragment(IndexHasFullTextCatalogMethodInfo, annotation.Value),
SqlServerAnnotationNames.FullTextChangeTracking
=> new MethodCallCodeFragment(IndexHasFullTextChangeTrackingMethodInfo, annotation.Value),

_ => null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public override void Generate(IModel model, CSharpRuntimeAnnotationCodeGenerator
annotations.Remove(SqlServerAnnotationNames.MaxDatabaseSize);
annotations.Remove(SqlServerAnnotationNames.PerformanceLevelSql);
annotations.Remove(SqlServerAnnotationNames.ServiceTierSql);
annotations.Remove(SqlServerAnnotationNames.FullTextCatalogs);
}

base.Generate(model, parameters);
Expand All @@ -50,6 +51,7 @@ public override void Generate(IRelationalModel model, CSharpRuntimeAnnotationCod
if (!parameters.IsRuntime)
{
var annotations = parameters.Annotations;
annotations.Remove(SqlServerAnnotationNames.FullTextCatalogs);
annotations.Remove(SqlServerAnnotationNames.MemoryOptimized);
annotations.Remove(SqlServerAnnotationNames.EditionOptions);
}
Expand Down Expand Up @@ -105,6 +107,10 @@ public override void Generate(IIndex index, CSharpRuntimeAnnotationCodeGenerator
annotations.Remove(SqlServerAnnotationNames.DataCompression);
annotations.Remove(SqlServerAnnotationNames.VectorIndexMetric);
annotations.Remove(SqlServerAnnotationNames.VectorIndexType);
annotations.Remove(SqlServerAnnotationNames.FullTextIndex);
annotations.Remove(SqlServerAnnotationNames.FullTextCatalog);
annotations.Remove(SqlServerAnnotationNames.FullTextChangeTracking);
annotations.Remove(SqlServerAnnotationNames.FullTextLanguages);
}

base.Generate(index, parameters);
Expand All @@ -124,6 +130,10 @@ public override void Generate(ITableIndex index, CSharpRuntimeAnnotationCodeGene
annotations.Remove(SqlServerAnnotationNames.DataCompression);
annotations.Remove(SqlServerAnnotationNames.VectorIndexMetric);
annotations.Remove(SqlServerAnnotationNames.VectorIndexType);
annotations.Remove(SqlServerAnnotationNames.FullTextIndex);
annotations.Remove(SqlServerAnnotationNames.FullTextCatalog);
annotations.Remove(SqlServerAnnotationNames.FullTextChangeTracking);
annotations.Remove(SqlServerAnnotationNames.FullTextLanguages);
}

base.Generate(index, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,61 @@ public static SqlServerVectorIndexBuilder HasVectorIndex(
return new SqlServerVectorIndexBuilder(indexBuilder);
}

/// <summary>
/// Configures a full-text index on the specified properties for SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <typeparam name="TEntity">The entity type being configured.</typeparam>
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param>
/// <param name="indexExpression">
/// A lambda expression representing the properties to include in the full-text index
/// (<c>blog => new { blog.Title, blog.Content }</c>).
/// </param>
/// <returns>A builder to further configure the full-text index.</returns>
public static SqlServerFullTextIndexBuilder<TEntity> HasFullTextIndex<TEntity>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
Expression<Func<TEntity, object?>> indexExpression)
where TEntity : class
{
Check.NotNull(indexExpression);

var indexBuilder = entityTypeBuilder.HasIndex(indexExpression);

// Having the FullTextIndex annotation (storing the KEY INDEX name) is what marks an index as a full-text index.
// The KEY INDEX name itself must be set later by the user via the builder API.
indexBuilder.Metadata.SetFullTextKeyIndex(null);

return new SqlServerFullTextIndexBuilder<TEntity>(indexBuilder);
}

/// <summary>
/// Configures a full-text index on the specified properties for SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param>
/// <param name="propertyNames">The names of the properties to include in the full-text index.</param>
/// <returns>A builder to further configure the full-text index.</returns>
public static SqlServerFullTextIndexBuilder HasFullTextIndex(
this EntityTypeBuilder entityTypeBuilder,
params string[] propertyNames)
{
Check.NotEmpty(propertyNames);

var indexBuilder = entityTypeBuilder.HasIndex(propertyNames);

// Having the FullTextIndex annotation (storing the KEY INDEX name) is what marks an index as a full-text index.
// The KEY INDEX name itself must be set later by the user via the builder API.
indexBuilder.Metadata.SetFullTextKeyIndex(null);

return new SqlServerFullTextIndexBuilder(indexBuilder);
}

/// <summary>
/// Configures a history table name for the entity mapped to a temporal table.
/// </summary>
Expand Down
Loading
Loading