I want to make the Middle Name of person optional. I have been using C#.net code first approach. For integer data type its easy just by using ?
operator to make in nullable. I am looking for a way to make my sting variable nullable. I tried to search but could not find the way to make it nullable.
Below is my code. Please suggest me how to make it nullable.
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; }
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…