I am trying to migrate a model using a DateTime property to a DateTimeOffset property.
When creating the migration, I get the following error:
The property 'MyProp' is of type 'DateTimeOffset' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
Why can't the C# type DateTimeOffset be mapped to the SQL Server Type datetimeoffset (Docs)?
Edit: Added Stacktrace
System.InvalidOperationException: The property 'MyProp' is of type 'DateTimeOffset' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
Edit added a reproduction
There is a reproduction on GitHub.
The issue is obvious, when taking a closer look at the data model. I have changed the type of the property to be
DateTimeOffset, but the EF Core type name is fixed using the attribute[Column("CreateDate", TypeName = "datetime")]. This creates an ambiguity.Reading the exception message confused me a little, because it states that the Type
DateTimeOffsetis not supported.