Asp.net core Asp.Net Core 3.1 MVC web应用程序与SqlDateTime的编译错误

Asp.net core Asp.Net Core 3.1 MVC web应用程序与SqlDateTime的编译错误,asp.net-core,asp.net-core-mvc,sqlclient,asp.net-core-3.1,Asp.net Core,Asp.net Core Mvc,Sqlclient,Asp.net Core 3.1,关于SqlDateTime的使用,我很难将我的web应用从2.2迁移到3.1。为了确保迁移过程中不会出现问题,我在Visual Studio 2019 16.4中使用标准asp.net core 3.1模板创建了一个新的MVC web应用程序。当我添加一个变量并将其分配给SqlDateTime时,我得到一个编译错误 类型“SqlDateTime”在“System.Data.Common”和“System.Data.Common”中都存在, 版本=4.2.2.0,区域性=中性,PublicKeyT

关于SqlDateTime的使用,我很难将我的web应用从2.2迁移到3.1。为了确保迁移过程中不会出现问题,我在Visual Studio 2019 16.4中使用标准asp.net core 3.1模板创建了一个新的MVC web应用程序。当我添加一个变量并将其分配给SqlDateTime时,我得到一个编译错误

类型“SqlDateTime”在“System.Data.Common”和“System.Data.Common”中都存在, 版本=4.2.2.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a'和 'System.Data.SqlClient,版本=4.1.0.0,区域性=中性, PublicKeyToken=b03f5f7f11d50a3a'

以前它在使用System.Data.SqlClient时工作,但我知道它在3.0中已被Microsoft.Data.SqlClient取代,但是后者没有SqlDateTime,因此获得它的唯一方法是使用System.Data.SqlTypes,但这会产生编译错误。我甚至还没有包括System.Data.SqlClient,所以我有点困惑为什么编译器会引用它。有什么想法吗

您有两个选择

  • 降级到3.0,3.1不支持

  • 使用1753年1月1日的
    MinValue
    创建您自己的结构


  • 检查值和支持的版本

    您需要降级到3.0<代码>sqlDateTimeStruct在3.1Great中不受支持!很高兴它有帮助!