我想使人的中间名(CMName
)可选。我一直在使用 C # .net 代码优先的方法。对于整数数据类型,只需使用 ?
运算符即可使其为空。我正在寻找一种方法,使我的刺变量为零。我试图搜索,但找不到办法使其无效。
下面是我的代码。请建议我如何使它为空。
public class ChildrenInfo
{
[Key]
public int ChidrenID { get; set; }
[Required]
[Display(Name ="First Name")]
[StringLength(50,ErrorMessage ="First Name cannot exceed more than 50 characters")]
[RegularExpression(@"^[A-Z]+[a-z]*$",ErrorMessage ="Name cannot have special character,numbers or space")]
[Column("FName")]
public string CFName { get; set; }
[Display(Name ="Middle Name")]
[RegularExpression(@"^[A-Z]+[a-z]*$",ErrorMessage ="Middle Name cannot have special character,numbers or space")]
[StringLength(35,ErrorMessage ="Middle Name cannot have more than 35 characters")]
[Column("MName")]
public string CMName { get; set; }
}