googleapis / googleapis/dotnet-spanner-entity-framework
migrations: nullable DATE columns break migrations
- Dominant language
- C#
- Stars
- 34
- Forks
- 13
- Avg merge
- 4h 39m
- Merged PRs (30d)
- 10
Description
#### Environment details
- Programming language: C#
- OS: windows
- Language runtime version: 8
- Package version: 3.8.0
#### Steps to reproduce
1. Use a nullable property that maps to DATE, e.g. SpannerDate? or DateOnly?
2. Create first migration
3. Attempt to remove migration or generate new migration
4. This errors
Example is this command in `Google.Cloud.EntityFrameworkCore.Spanner.IntegrationTests`:
```console
dotnet ef migrations add test --context TestMigrationDbContext --output-dir MigrationTests/Migrations
```
The above errors with:
```
\Google.Cloud.EntityFrameworkCore.Spanner.IntegrationTests> dotnet ef migrations add AddOrderedIndex --context TestMigrationDbContext --output-dir MigrationTests/Migrations
Build started...
Build succeeded.
System.InvalidOperationException: No coercion operator is defined between types 'System.Nullable`1[System.DateTime]' and 'Google.Cloud.EntityFrameworkCore.Spanner.Storage.SpannerDate'.
at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ValueComparerExtensions.ToNullableComparer(ValueComparer valueComparer, Type clrType)
at Microsoft.EntityFrameworkCore.Metadata.Internal.Property.GetKeyValueComparer()
at Microsoft.EntityFrameworkCore.Metadata.Internal.Property.GetProviderValueComparer()
at Microsoft.EntityFrameworkCore.Metadata.Internal.Property.Microsoft.EntityFrameworkCore.Metadata.IProperty.GetProviderValueComparer()
at Microsoft.EntityFrameworkCore.Metadata.Internal.ColumnBase`1.Microsoft.EntityFrameworkCore.Metadata.IColumnBase.get_ProviderValueComparer()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IColumn source, IColumn target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
No coercion operator is defined between types 'System.Nullable`1[System.DateTime]' and 'Google.Cloud.EntityFrameworkCore.Spanner.Storage.SpannerDate'.
```
This means migrations are stuck since the snapshot has a type of DateTime? mapped to a DATE field which causes this problem, breaking any changes going in.
Contributor guide
Assessment
This issue has not been assessed yet.