Skip to content

Commit 8b88d60

Browse files
committed
Support keys and indexes that traverse complex-type properties
Fixes #31246 Fixes #28605
1 parent baa5c13 commit 8b88d60

89 files changed

Lines changed: 3487 additions & 456 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,10 @@ protected virtual void ValidateVectorIndex(
514514
string.Join(",", index.Properties.Select(e => e.Name))));
515515
}
516516

517-
if (index.Properties[0].GetVectorDistanceFunction() == null
518-
|| index.Properties[0].GetVectorDimensions() == null)
517+
var firstIndexProperty = index.Properties[0] as IProperty;
518+
if (firstIndexProperty == null
519+
|| firstIndexProperty.GetVectorDistanceFunction() == null
520+
|| firstIndexProperty.GetVectorDimensions() == null)
519521
{
520522
throw new InvalidOperationException(
521523
CosmosStrings.VectorIndexOnNonVector(
@@ -542,7 +544,9 @@ protected virtual void ValidateFullTextIndex(
542544
string.Join(",", index.Properties.Select(e => e.Name))));
543545
}
544546

545-
if (index.Properties[0].GetIsFullTextSearchEnabled() != true)
547+
var firstFullTextProperty = index.Properties[0] as IProperty;
548+
if (firstFullTextProperty == null
549+
|| firstFullTextProperty.GetIsFullTextSearchEnabled() != true)
546550
{
547551
throw new InvalidOperationException(
548552
CosmosStrings.FullTextIndexOnNonFullTextProperty(

src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private static async Task<bool> CreateContainerIfNotExistsOnceAsync(
199199
}
200200

201201
vectorIndexes.Add(
202-
new VectorIndexPath { Path = GetJsonPropertyPathFromRoot(index.Properties[0]), Type = vectorIndexType.Value });
202+
new VectorIndexPath { Path = GetJsonPropertyPathFromRoot((IReadOnlyProperty)index.Properties[0]), Type = vectorIndexType.Value });
203203
}
204204

205205
if (index.IsFullTextIndex() == true)
@@ -213,7 +213,7 @@ private static async Task<bool> CreateContainerIfNotExistsOnceAsync(
213213
}
214214

215215
fullTextIndexPaths.Add(
216-
new FullTextIndexPath { Path = GetJsonPropertyPathFromRoot(index.Properties[0]) });
216+
new FullTextIndexPath { Path = GetJsonPropertyPathFromRoot((IReadOnlyProperty)index.Properties[0]) });
217217
}
218218
}
219219

src/EFCore.Design/Properties/DesignStrings.Designer.cs

Lines changed: 53 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/EFCore.Design/Properties/DesignStrings.resx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@
126126
<data name="BadMigrationName" xml:space="preserve">
127127
<value>The migration name '{name}' is not valid. Migration names cannot contain any of the following characters: '{characters}'.</value>
128128
</data>
129-
<data name="MigrationNameRequired" xml:space="preserve">
130-
<value>A migration name must be specified.</value>
131-
</data>
132129
<data name="BadSequenceType" xml:space="preserve">
133130
<value>Sequence '{sequenceName}' cannot be scaffolded because it uses type '{typeName}' which is unsupported.</value>
134131
</data>
@@ -193,6 +190,9 @@ Consider changing your target project to the DbContext project by using the Pack
193190
<data name="CouldNotGetInterceptableLocation" xml:space="preserve">
194191
<value>Couldn't get interceptable location for: '{node}'.</value>
195192
</data>
193+
<data name="CreatingAndApplyingMigration" xml:space="preserve">
194+
<value>Creating and applying migration '{migrationName}'.</value>
195+
</data>
196196
<data name="DatabaseDropped" xml:space="preserve">
197197
<value>Successfully dropped database '{name}'.</value>
198198
</data>
@@ -208,6 +208,9 @@ Consider changing your target project to the DbContext project by using the Pack
208208
<data name="DuplicateMigrationName" xml:space="preserve">
209209
<value>The name '{migrationName}' is used by an existing migration.</value>
210210
</data>
211+
<data name="DynamicMigrationNotFound" xml:space="preserve">
212+
<value>The dynamic migration '{migrationId}' was not found. Only migrations applied in the current session using CreateAndApplyMigration can be reverted.</value>
213+
</data>
211214
<data name="DynamicQueryNotSupported" xml:space="preserve">
212215
<value>Dynamic LINQ queries are not supported when precompiling queries.</value>
213216
</data>
@@ -289,14 +292,27 @@ Consider changing your target project to the DbContext project by using the Pack
289292
<data name="ManuallyDeleted" xml:space="preserve">
290293
<value>The model snapshot and the backing model of the last migration are different. Continuing under the assumption that the last migration was deleted manually.</value>
291294
</data>
295+
<data name="MigrationCompilationFailed" xml:space="preserve">
296+
<value>Failed to compile migration '{migrationId}'. Errors:
297+
{errors}</value>
298+
</data>
299+
<data name="MigrationCreatedAndApplied" xml:space="preserve">
300+
<value>Migration '{migrationId}' was successfully created and applied.</value>
301+
</data>
292302
<data name="MigrationDescription" xml:space="preserve">
293303
<value>The target migration. If '0', all migrations will be reverted. Defaults to the last migration.</value>
294304
</data>
305+
<data name="MigrationNameRequired" xml:space="preserve">
306+
<value>A migration name must be specified.</value>
307+
</data>
295308
<data name="MigrationsAssemblyMismatch" xml:space="preserve">
296309
<value>Your target project '{assembly}' doesn't match your migrations assembly '{migrationsAssembly}'. Either change your target project or change your migrations assembly.
297310
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b =&gt; b.MigrationsAssembly("{assembly}")). By default, the migrations assembly is the assembly containing the DbContext.
298311
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.</value>
299312
</data>
313+
<data name="MigrationTypeNotFound" xml:space="preserve">
314+
<value>Could not find migration type with ID '{migrationId}' in the compiled assembly.</value>
315+
</data>
300316
<data name="MSBuildWorkspaceDiagnostics" xml:space="preserve">
301317
<value>MSBuild Workspace diagnostics:{diagnostics}</value>
302318
</data>
@@ -342,6 +358,9 @@ Change your target project to the migrations project by using the Package Manage
342358
<data name="NoDesignTimeServices" xml:space="preserve">
343359
<value>No design-time services were found.</value>
344360
</data>
361+
<data name="NoDynamicMigrationsToRevert" xml:space="preserve">
362+
<value>No dynamic migrations have been applied in the current session. Only migrations applied using CreateAndApplyMigration can be reverted with RevertMigration.</value>
363+
</data>
345364
<data name="NoLanguageService" xml:space="preserve">
346365
<value>The project language '{language}' isn't supported by the built-in {service} service. You can try looking for an additional NuGet package which supports this language; moving your DbContext type to a C# class library referenced by this project; or manually implementing and registering the design-time service for the programming language.</value>
347366
</data>
@@ -360,12 +379,6 @@ Change your target project to the migrations project by using the Package Manage
360379
<data name="NoPendingModelChanges" xml:space="preserve">
361380
<value>No changes have been made to the model since the last migration.</value>
362381
</data>
363-
<data name="NoDynamicMigrationsToRevert" xml:space="preserve">
364-
<value>No dynamic migrations have been applied in the current session. Only migrations applied using CreateAndApplyMigration can be reverted with RevertMigration.</value>
365-
</data>
366-
<data name="DynamicMigrationNotFound" xml:space="preserve">
367-
<value>The dynamic migration '{migrationId}' was not found. Only migrations applied in the current session using CreateAndApplyMigration can be reverted.</value>
368-
</data>
369382
<data name="NoReferencedServices" xml:space="preserve">
370383
<value>No referenced design-time services were found.</value>
371384
</data>
@@ -499,17 +512,4 @@ Change your target project to the migrations project by using the Package Manage
499512
<data name="WritingSnapshot" xml:space="preserve">
500513
<value>Writing model snapshot to '{file}'.</value>
501514
</data>
502-
<data name="MigrationCompilationFailed" xml:space="preserve">
503-
<value>Failed to compile migration '{migrationId}'. Errors:
504-
{errors}</value>
505-
</data>
506-
<data name="MigrationTypeNotFound" xml:space="preserve">
507-
<value>Could not find migration type with ID '{migrationId}' in the compiled assembly.</value>
508-
</data>
509-
<data name="CreatingAndApplyingMigration" xml:space="preserve">
510-
<value>Creating and applying migration '{migrationName}'.</value>
511-
</data>
512-
<data name="MigrationCreatedAndApplied" xml:space="preserve">
513-
<value>Migration '{migrationId}' was successfully created and applied.</value>
514-
</data>
515515
</root>

src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by a tool.
4-
// Runtime Version: 17.0.0.0
4+
// Runtime Version: 18.0.0.0
55
//
66
// Changes to this file may cause incorrect behavior and will be lost if
77
// the code is regenerated.
@@ -21,7 +21,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
2121
/// <summary>
2222
/// Class to produce the template output
2323
/// </summary>
24-
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")]
24+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")]
2525
public partial class CSharpEntityTypeGenerator : CSharpEntityTypeGeneratorBase
2626
{
2727
/// <summary>
@@ -400,7 +400,7 @@ public virtual void Initialize()
400400
/// <summary>
401401
/// Base class for this transformation
402402
/// </summary>
403-
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")]
403+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")]
404404
public class CSharpEntityTypeGeneratorBase
405405
{
406406
#region Fields
@@ -415,7 +415,7 @@ public class CSharpEntityTypeGeneratorBase
415415
/// <summary>
416416
/// The string builder that generation-time code is using to assemble generated output
417417
/// </summary>
418-
protected System.Text.StringBuilder GenerationEnvironment
418+
public System.Text.StringBuilder GenerationEnvironment
419419
{
420420
get
421421
{

0 commit comments

Comments
 (0)