EF 6 IsRequired() allowing empty strings


In past projects with versions of EF5 and EF4, the IsRequired() fluent API method would thrown a DbEntityValidationException if the property was null or an empty string. In my current project utilizng EF6, The DBEntityValidationException is not thrown when the string property is empty.


public class Application : BaseEntity
    public string Name { get; set; }

    // navigation properties
    public IList<Role> Roles { get; set; }


internal class ApplicationMapping : EntityTypeConfiguration<Application>
    public ApplicationMapping()
        // table name

        // properties
        this.Property(t => t.Name)

After pouring over the MSDN EF documentation and stack overflow, I am at a loss for why this is happening. Did a convention get added/modified to EF6?

Popular Answer

These days you can still use [Required] attribute and have configurable AllowEmptyStrings

[Required(AllowEmptyStrings = false)]

False is default

Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why