【问题标题】:EF's DatabaseGeneratedOption.Identity attribute doesn't work for the ulong typeEF 的 DatabaseGeneratedOption.Identity 属性不适用于 ulong 类型
【发布时间】:2014-11-09 07:45:14
【问题描述】:
[Table( "User" )]
public class User
{
    [Key]
    [DatabaseGeneratedAttribute( DatabaseGeneratedOption.Identity )]
    public ulong Id { get; set; }
    // other columns
}

对于这段代码,我得到了异常:

System.Data.Entity.Edm.EdmEntityType: : EntityType 'User' 没有键 定义。定义此 EntityType 的键。

但是将 Id 的类型更改为 int,一切正常。

    //...
    [DatabaseGeneratedAttribute( DatabaseGeneratedOption.Identity )]
    public int Id { get; set; }
    //...

如何获得自动创建具有 ulong 类型容量的 Id 的表的可能性? (显然是先用ef的代码)

【问题讨论】:

  • 为什么不直接使用 long/int64。我发现我很难相信你会创造比它所能容纳的更多的记录。

标签: c# asp.net asp.net-mvc entity-framework ef-code-first


【解决方案1】:

鉴于数字 sql 服务器类型是:

bigint、numeric、bit、smallint、decimal、smallmoney、int、tinyint、money

很明显,CLR 类型 UInt64 (ulong) 不映射到任何这些类型。

【讨论】:

  • TIL:SQL Server 不支持无符号整数。怎么回事?只使用了几年,从来没有个人需要未签名的,所以我只是假设它可以,因为每个。臭。其他。数据库。在里面。世界。能够。哦,好吧。
猜你喜欢
  • 1970-01-01
  • 2023-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-27
  • 2012-06-14
  • 1970-01-01
  • 2014-10-06
相关资源
最近更新 更多