Migration generation fails for SqlVector<float>
Bug description
Trying to follow the instructions found at: https://learn.microsoft.com/en-us/ef/core/providers/sql-server/vector-search?tabs=fluent-api
It works for a completely fresh project where only an initial migration needs to be generated.
For existing EF project, it fails with:
The type mapping for 'SqlVector
' has not implemented code literal generation.
Your code
Unzip northwindload.zip and run dotnet ef migrations add AddFeedbacks
Stack traces
System.NotSupportedException: The type mapping for 'SqlVector<float>' has not implemented code literal generation.
at Microsoft.EntityFrameworkCore.Storage.CoreTypeMapping.GenerateCodeLiteral(Object value)
at Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper.UnknownLiteral(Object value)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(AddColumnOperation operation, IndentedStringBuilder builder)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName, IReadOnlyList`1 operations, IndentedStringBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(String migrationNamespace, String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language, Boolean dryRun)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace, Boolean dryRun)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace, Boolean dryRun)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Verbose output
Using project 'C:\repos\visma\NorthwindLoad\NorthwindLoad.csproj'.
Using startup project 'C:\repos\visma\NorthwindLoad\NorthwindLoad.csproj'.
dotnet msbuild /getProperty:ProjectName /getProperty:AssemblyName /getProperty:DesignAssembly /getProperty:Language /getProperty:OutputPath /getProperty:PlatformTarget /getProperty:ProjectAssetsFile /getProperty:ProjectDir /getProperty:RootNamespace /getProperty:RuntimeFrameworkVersion /getProperty:TargetFileName /getProperty:TargetFrameworkMoniker /getProperty:Nullable /getProperty:TargetFramework /getProperty:TargetPlatformIdentifier /getProperty:Platform /t:ResolvePackageAssets /getItem:RuntimeCopyLocalItems C:\repos\visma\NorthwindLoad\NorthwindLoad.csproj
dotnet msbuild /getProperty:ProjectName /getProperty:AssemblyName /getProperty:DesignAssembly /getProperty:Language /getProperty:OutputPath /getProperty:PlatformTarget /getProperty:ProjectAssetsFile /getProperty:ProjectDir /getProperty:RootNamespace /getProperty:RuntimeFrameworkVersion /getProperty:TargetFileName /getProperty:TargetFrameworkMoniker /getProperty:Nullable /getProperty:TargetFramework /getProperty:TargetPlatformIdentifier /getProperty:Platform /t:ResolvePackageAssets /getItem:RuntimeCopyLocalItems C:\repos\visma\NorthwindLoad\NorthwindLoad.csproj
Build started...
dotnet build C:\repos\visma\NorthwindLoad\NorthwindLoad.csproj /verbosity:quiet /nologo /p:PublishAot=false
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:02.14
Build succeeded.
dotnet exec --depsfile C:\repos\visma\NorthwindLoad\bin\Debug\net10.0\NorthwindLoad.deps.json --additionalprobingpath C:\Users\rm\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\repos\visma\NorthwindLoad\bin\Debug\net10.0\NorthwindLoad.runtimeconfig.json C:\Users\rm\.dotnet\tools\.store\dotnet-ef\10.0.0\dotnet-ef\10.0.0\tools\net10.0\any\tools\net10.0\any\ef.dll migrations add AddFeedbacks --assembly C:\repos\visma\NorthwindLoad\bin\Debug\net10.0\NorthwindLoad.dll --project C:\repos\visma\NorthwindLoad\NorthwindLoad.csproj --startup-assembly C:\repos\visma\NorthwindLoad\bin\Debug\net10.0\NorthwindLoad.dll --startup-project C:\repos\visma\NorthwindLoad\NorthwindLoad.csproj --project-dir C:\repos\visma\NorthwindLoad\ --root-namespace NorthwindLoad --language C# --framework net10.0 --design-assembly C:\Users\rm\.nuget\packages\microsoft.entityframeworkcore.design\10.0.0\lib\net10.0\Microsoft.EntityFrameworkCore.Design.dll --nullable --working-dir C:\repos\visma\NorthwindLoad --verbose
Using assembly 'NorthwindLoad'.
Using startup assembly 'NorthwindLoad'.
Using application base 'C:\repos\visma\NorthwindLoad\bin\Debug\net10.0'.
Using working directory 'C:\repos\visma\NorthwindLoad'.
Using root namespace 'NorthwindLoad'.
Using project directory 'C:\repos\visma\NorthwindLoad\'.
Remaining arguments: .
Finding DbContext classes...
Using environment 'Development'.
Finding IDesignTimeDbContextFactory implementations...
Finding DbContext classes in the project...
Found DbContext 'NorthwindDbContext'.
Finding application service provider in assembly 'NorthwindLoad'...
Finding Microsoft.Extensions.Hosting service provider...
Using application service provider from Microsoft.Extensions.Hosting.
Using context 'NorthwindDbContext'.
Finding design-time services referenced by assembly 'NorthwindLoad'...
Finding design-time services referenced by assembly 'NorthwindLoad'...
No referenced design-time services were found.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'NorthwindLoad'...
No design-time services were found.
System.NotSupportedException: The type mapping for 'SqlVector<float>' has not implemented code literal generation.
at Microsoft.EntityFrameworkCore.Storage.CoreTypeMapping.GenerateCodeLiteral(Object value)
at Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper.UnknownLiteral(Object value)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(AddColumnOperation operation, IndentedStringBuilder builder)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName, IReadOnlyList`1 operations, IndentedStringBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(String migrationNamespace, String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language, Boolean dryRun)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace, Boolean dryRun)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace, Boolean dryRun)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The type mapping for 'SqlVector<float>' has not implemented code literal generation.
EF Core version
10.0.0
Database provider
No response
Target framework
.Net 10.0
Operating system
No response
IDE
Visual Studio 2026
This happens only when adding a non-nullable vector column to an existing table: EF attempts to generate a default value for the vector in that scenario, causing the exception to get thrown. At least as a workaround, make the vector property nullable, and then possibly make it non-nullable afterwards once embeddings have been populated for all rows.
Otherwise... I can implement GenerateCodeLiteral on SqlServerVectorTypeMapping - but unfortunately it looks like it wouldn't help this case... Our current implementation gets to CSharpHelper.Unknown, where we call FindMapping with only the CLR type; in other words, the type mapping on which GenerateCodeLiteral would be called has no idea how many dimensions the vector property is configured with; and since the actual vector passed in will be zero-dimensional (default), we can't actually generate meaningful code for the default value that would actually work.
In other words, our current code generation assumes that code literals can be generated without having the actual type mapping as configured by the user, including facets like dimensions. This breaks assumption breaks down with vector.
@AndriySvyryd does this ring any bells? Any ideas about what we could do here?
Thank you.
make the vector property nullable
It turns out this is what I wanted anyway. I wrongly assumed I could default to an empty array, but afaict sql server expects me to fill the array completely each time.
I'm keeping an eye on #37281 now.
@AndriySvyryd assigning to you as it's a migration code generation issue - seems like we may need to change the architecture there a bit. Though let me know if you think I should look.