有没有理由像这样指定每个表中的所有列
this.HasKey(t => t.EmployeeID);
// Properties
this.Property(t => t.LastName)
.IsRequired()
.HasMaxLength(20);
如果是,为什么?
答案 0 :(得分:2)
如果您询问是否有其他方式指定not null
和nvarchar(n)
,您还可以使用System.ComponentModel.DataAnnotations
命名空间中的属性。
public class Employee
{
[Key]
public int EmployeeID { get; set; }
[Required]
[MaxLength(20)]
public string LastName { get; set; }
}