实体框架核心不会在代码优先迁移中映射DateTimeOffSet

时间:2019-10-02 02:40:13

标签: sql-server .net-core ef-code-first entity-framework-core ef-migrations

将模型更改为DateTimeOffset后,我尝试运行Add-Migration,但是会产生错误。

The property 'Session.StartTime' is of type 'DateTimeOffset' which is not
supported by current database provider. Either change the property CLR type or 
ignore the property using the '[NotMapped]' attribute or by using 
'EntityTypeBuilder.Ignore' in 'OnModelCreating'

很显然,我很乐意做这项工作,我可以做些什么来解决它? 我尝试将上下文的OnModelCreating更改为。

entity.Property(e => e.StartTime)
                .HasColumnName("start_time")
                .HasColumnType("datetime2");

以及列类型datetimeoffset一样,当我尝试添加迁移时,它们都无法正常工作并仍然导致错误。

任何人都曾经经历过吗?我知道SQL Server支持DateTimeOffsets,不知道为什么这是一个问题。

0 个答案:

没有答案