简体   繁体   中英

Try on SaveChanges Entity FrameWork 5

I am using Code First.

execute

            try
        {
            _context.SaveChanges();
        }
        catch (EntityException e)
        {

        }

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

            this.Property(t => t.Senha)
            .HasMaxLength(15);

I forced a password greater than 15 characters, catch will never execute, why?

The error occurs at validating the entity resulting in a DbEntityValidationException .

So try

catch (DbEntityValidationException e)
{

}

maybe you are catching incorrect exception. try this :

     try
    {
        _context.SaveChanges();
    }
    catch (DbEntityValidationException e)
    {

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM