gpt4 book ai didi

c# - EF 的 DatabaseGeneratedOption.Identity 属性不适用于 ulong 类型

转载 作者:行者123 更新时间:2023-11-30 17:46:43 25 4
gpt4 key购买 nike

[Table( "User" )]
public class User
{
[Key]
[DatabaseGeneratedAttribute( DatabaseGeneratedOption.Identity )]
public ulong Id { get; set; }
// other columns
}

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

System.Data.Entity.Edm.EdmEntityType: : EntityType 'User' has no key defined. Define the key for this EntityType.

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

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

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

最佳答案

鉴于数字 sql server 类型是:

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

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

关于c# - EF 的 DatabaseGeneratedOption.Identity 属性不适用于 ulong 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25853864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com