下面是在 EF code first中同时使用 [MaxLength]和 [StringLength]属性时的结果。如果两者都使用,[MaxLength]将赢得比赛。请参阅下面类中 studentname列的测试结果
public class Student
{
public Student () {}
[Key]
[Column(Order=1)]
public int StudentKey { get; set; }
//[MaxLength(50),StringLength(60)] //studentname column will be nvarchar(50)
//[StringLength(60)] //studentname column will be nvarchar(60)
[MaxLength(50)] //studentname column will be nvarchar(50)
public string StudentName { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
}