我在MVC中制作代码优先方法来生成表。我试图让我的Employee类的主键是防止负值,但显然,我总是得到一个例外。是否有int类型的装饰代码以防止否定或解决方法允许uint作为主键?
public class Employee
{
[Key]
[Column(Order = 0)]
public uint EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public decimal Salary { get; set; }
}
看看this。
除此之外,uint不是CLS compliant,因此通常不建议使用