代码之家  ›  专栏  ›  技术社区  ›  t3chb0t

数据类型前缀为“类型X不是定义的系统类型”的列出错

  •  0
  • t3chb0t  · 技术社区  · 7 年前

    我正在使用第三方数据库。通常,我在linqpad中编写的查询,稍后转换为实体框架核心(2.1),可以毫无问题地工作。不过,这一次不行。

    当我尝试使用“状态”列时,我得到以下信息

    class 16 byte
    第1行int
    消息“类型枚举不是定义的系统类型。”字符串
    数字243 int
    过程“”字符串
    服务器“…”字符串
    源“.net sqlclient data provider”字符串
    状态2字节
    

    因此,我打开了SQL Server Management Studio,发现此列(以及少数其他列)使用了stragedata types:。

    有了stragei mean they are prefixed like here withenumerationorcurrencycode:varchar(3)etc.。

    我使用EF核心脚手架创建实体,属性定义为:

    public short status_get;set;
    

    看起来不错,但EF核心引擎显然识别了枚举前缀,并在onmodelcreating>方法中生成了此行:

    entity.property(e=>e.status).HasColumnType(“枚举”);
    

    我想这是导致错误的原因。


    我以前从未见过这样的情况,我想知道为什么ef core无法查询这样的列,而linqpand没有,这些奇怪的数据类型是什么?

    有没有任何magicsecretoption for ef core to fix this issue?

    当我尝试使用这个列时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,发现此列(以及其他一些列)使用边条数据类型:

    enter image description here

    具有边条我的意思是它们的前缀是EnumerationCurrencyCode:varchar(3)等。

    我使用EF核心脚手架创建实体,属性定义为:

    public short Status { get; set; }
    

    看上去不错,但英孚核心引擎显然认识到枚举前缀并在OnModelCreating方法:

    entity.Property(e => e.Status).HasColumnType("Enumeration");
    

    我想这是导致错误的原因。


    我以前从未见过这样的情况,我想知道为什么ef core无法查询这样的列,而linqpand没有,这些奇怪的数据类型是什么?

    有吗魔术秘密EF核心解决此问题的选项?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Damien_The_Unbeliever    7 年前

    create type Enumeration from smallint null
    go
    create table T (
        ID int not null,
        E Enumeration not null
    )
    


    RULE

    推荐文章