Entity Framework 6 RC1中的EntityTypeConfiguration

时间:2013-09-10 08:53:35

标签: entity-framework

有没有理由像这样指定每个表中的所有列

this.HasKey(t => t.EmployeeID);

            // Properties
            this.Property(t => t.LastName)
                .IsRequired()
                .HasMaxLength(20);

如果是,为什么?

1 个答案:

答案 0 :(得分:2)

如果您询问是否有其他方式指定not nullnvarchar(n),您还可以使用System.ComponentModel.DataAnnotations命名空间中的属性。

public class Employee
{
    [Key]
    public int EmployeeID { get; set; }

    [Required]
    [MaxLength(20)]
    public string LastName { get; set; }
}