Asp.Net Core 3.1 MVC Web 应用程序使用 SqlDateTime 编译错误

Asp.Net Core 3.1 MVC web application compile error with SqlDateTime

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

The type 'SqlDateTime' exists in both 'System.Data.Common, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

以前它曾经在使用 System.Data.SqlClient 时工作,但我知道这在 3.0 中已被替换为 Microsoft.Data.SqlClient 但是后者没有 SqlDateTime 所以唯一的方法是通过使用 System.Data.SqlTypes 但这会产生编译错误。我什至没有包括 System.Data.SqlClient 所以我有点困惑为什么它仍然被编译器引用。有什么想法吗?

您有 2 个选择。

  1. 降级到3.0,3.1不支持。

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

检查 here 值和支持的版本