System.InvalidCastException,带有tinyint标识列的实体框架

时间:2016-02-04 04:22:34

标签: entity-framework-6

以下代码运行时

var op = context.Operation.SingleOrDefault(x => x.Operation1 == null);

我收到错误

  System.InvalidCastException was unhandled
  HResult=-2147467262
  Message=Specified cast is not valid.
  Source=System.Data
  StackTrace:
       at System.Data.SqlClient.SqlBuffer.get_Byte()
  InnerException: 

我注意到EF 6.1.3已将列Operation映射到名称Operation1,因为该表也称为Operation

表结构有

[OperationID] [tinyint] IDENTITY(1,1) NOT NULL,
[Operation] [varchar](255) NULL

1 个答案:

答案 0 :(得分:1)

[System.ComponentModel.DataAnnotations.Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public byte EntidadeID { get; set; }