Skip to content
Open
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 @@ -325,6 +325,10 @@ protected virtual void ValidateFullTextIndex(

var entityType = index.DeclaringEntityType;

ValidateUnsupportedIndexOptions(
index,
(option) => SqlServerStrings.FullTextIndexUnsupportedOption(index.DisplayName(), entityType.DisplayName(), option));

if (++_entityFullTextIndexCount > 1)
{
throw new InvalidOperationException(
Expand Down Expand Up @@ -384,6 +388,11 @@ protected virtual void ValidateVectorIndex(IIndex index)
{
if (index.IsVectorIndex())
{
ValidateUnsupportedIndexOptions(
index,
(option) => SqlServerStrings.VectorIndexUnsupportedOption(
index.DisplayName(), index.DeclaringEntityType.DisplayName(), option));

if (index.Properties is not [var propertyBase])
{
throw new InvalidOperationException(
Expand Down Expand Up @@ -420,6 +429,28 @@ protected virtual void ValidateVectorIndex(IIndex index)
}
}

private static void ValidateUnsupportedIndexOptions(IIndex index, Func<string, string> errorFactory)
{
var option = index switch
{
{ IsUnique: true } => nameof(index.IsUnique),
{ IsDescending: not null } => nameof(index.IsDescending),
_ when index.GetFilter() is not null => "Filter",
_ when index.IsClustered() is not null => "IsClustered",
_ when index.GetIncludeProperties() is not null => "IncludeProperties",
_ when index.GetFillFactor() is not null => "FillFactor",
_ when index.IsCreatedOnline() is not null => "IsCreatedOnline",
_ when index.GetSortInTempDb() is not null => "SortInTempDb",
_ when index.GetDataCompression() is not null => "DataCompression",
_ => null
};

if (option is not null)
{
throw new InvalidOperationException(errorFactory(option));
}
}

/// <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 Down
16 changes: 16 additions & 0 deletions src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/EFCore.SqlServer/Properties/SqlServerStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@
<data name="FullTextIndexOnInvalidColumn" xml:space="preserve">
<value>Full-text index '{index}' on entity type '{entityType}' includes property '{property}' which is not mapped to a text or varbinary column type supported by full-text search.</value>
</data>
<data name="FullTextIndexUnsupportedOption" xml:space="preserve">
<value>Full-text index '{index}' on entity type '{entityType}' was configured with the '{option}' option, which is not supported on full-text indexes.</value>
</data>
<data name="FullTextMultipleDefaultCatalogs" xml:space="preserve">
<value>Multiple full-text catalogs are marked as default. Only one full-text catalog can be the default.</value>
</data>
Expand Down Expand Up @@ -427,6 +430,9 @@
<data name="VectorIndexRequiresType" xml:space="preserve">
<value>Vector index '{index}' on entity type '{entityType}' cannot have an empty vector index type.</value>
</data>
<data name="VectorIndexUnsupportedOption" xml:space="preserve">
<value>Vector index '{index}' on entity type '{entityType}' was configured with the '{option}' option, which is not supported on vector indexes.</value>
</data>
<data name="VectorPropertiesNotSupportedInJson" xml:space="preserve">
<value>Vector property '{propertyName}' is on '{structuralType}' which is mapped to JSON. Vector properties are not supported within JSON documents.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,28 @@ public virtual void Throws_for_vector_index_on_non_vector_property()
modelBuilder);
}

[Fact]
[Experimental("EF9105")]
public virtual void Throws_for_vector_index_with_unsupported_option()
{
var modelBuilder = CreateConventionModelBuilder();

modelBuilder.Entity<VectorWithoutDimensionsEntity>(
b =>
{
b.Property(e => e.Vector).HasMaxLength(3);
var indexBuilder = b.HasVectorIndex(e => e.Vector).HasMetric("cosine");
indexBuilder.Metadata.SetDataCompression(DataCompressionType.Page);
});

VerifyError(
SqlServerStrings.VectorIndexUnsupportedOption(
"{'Vector'}",
nameof(VectorWithoutDimensionsEntity),
"DataCompression"),
modelBuilder);
}

public class VectorWithoutDimensionsEntity
{
public int Id { get; set; }
Expand Down Expand Up @@ -1551,6 +1573,25 @@ public virtual void Throws_for_full_text_index_with_mixed_valid_and_invalid_colu
modelBuilder);
}

[Fact]
public virtual void Throws_for_full_text_index_with_unsupported_option()
{
var modelBuilder = CreateConventionModelBuilder();

modelBuilder.Entity<FullTextEntityValid>(b =>
{
var indexBuilder = b.HasFullTextIndex(e => e.Title).UseKeyIndex("PK_FullTextEntityValid");
indexBuilder.Metadata.IsUnique = true;
});

VerifyError(
SqlServerStrings.FullTextIndexUnsupportedOption(
"{'Title'}",
nameof(FullTextEntityValid),
"IsUnique"),
modelBuilder);
}

public class FullTextEntityWithTwoIndexes
{
public int Id { get; set; }
Expand Down
Loading