【发布时间】:2018-12-19 04:50:09
【问题描述】:
我正在使用第 3 方数据库。通常,我在 LINQPad 中编写并随后转换为 Entity Framework Core (2.1) 的查询可以正常工作。不过,这次不行。
当我尝试使用Status 列时,我得到以下SqlException:
Class 16 byte LineNumber 1 int Message "Type Enumeration is not a defined system type." string Number 243 int Procedure "" string Server "..." string Source ".Net SqlClient Data Provider" string State 2 byte
于是我打开了 SQL Server Management Studio,发现这个专栏(以及其他一些专栏)使用了 stage 数据类型:
with stage 我的意思是它们的前缀就像这里的 Enumeration 或 CurrencyCode:varchar(3) 等。
我使用 EF-Core 脚手架创建实体,属性定义为:
public short Status { get; set; }
看起来不错,但 EF-Core 引擎显然识别了 Enumeration 前缀并在 OnModelCreating 方法中生成了这一行:
entity.Property(e => e.Status).HasColumnType("Enumeration");
我猜这是导致错误的原因。
我以前从未见过这种情况,我想知道为什么 EF-Core 无法查询此类列而 LINQPand 却没有,这些奇怪的数据类型是什么?
EF-Core 是否有任何 magic 或 secret 选项来解决此问题?
【问题讨论】:
-
请参阅this 答案以获得解决方法。
标签: c# tsql entity-framework-core sql-server-2014