HockChai Lim
HockChai Lim

Reputation: 1713

EF6 - Annotation to allow empty string but not allow null

In EF6, is there a annotation that will allow empty string but not allow null?

I've tried [Required]. But this annotation does not allow empty string or null.

[Required]
[MaxLength(80)]
public string ShortDescription { get; set; }

Upvotes: 12

Views: 8295

Answers (1)

HockChai Lim
HockChai Lim

Reputation: 1713

Looks like I just need to add the (AllowEmptyStrings = true) option to the [Required] annotation.

[Required(AllowEmptyStrings = true)]
[MaxLength(80)]
public string ShortDescription { get; set; }

Upvotes: 17

Related Questions