EF 6 IsRequired() allowing empty strings

entity-framework entity-framework-6

Question

If the property was empty or null in earlier EF5 and EF4 applications, the IsRequired() fluent API method would throw a DbEntityValidationException. The DBEntityValidationException is not raised in my current project using EF6 when the string property is empty.

Entity:

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

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

Configuration:

internal class ApplicationMapping : EntityTypeConfiguration<Application>
{
    public ApplicationMapping()
    {
        // table name
        this.ToTable("Applications");

        // properties
        this.Property(t => t.Name)
            .IsRequired()
            .HasMaxLength(100);
    }
}

I've read over the MSDN EF documentation and stack overflow in great detail, but I still don't understand why this is happening. Did EF6 get a new/modified convention?

1
15
12/16/2013 7:50:24 PM

Popular Answer

ZZZ_tmp
27
11/7/2016 6:09:58 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow