title: Entity Framework Core DbUpdateException detailed information
body: <p>I am just getting started with EF Core in my full .net 4.5.2 project and am trying to do an integration test to validate I can insert a new student. </p>
  
  <p>The issue is, I want to be able to get better information from the exception being thrown as to why it is not inserting into the database.</p>
  
  <p>Here is my integration test code:</p>
  
  <pre><code>    [Fact]
      public void save_the_new_student_to_the_database()
      {
          var fixture = new Fixture();
          var optionsBuilder = new DbContextOptionsBuilder&lt;TestDbContext&gt;();
          //optionsBuilder.UseInMemoryDatabase();
          optionsBuilder.UseSqlServer("Server = (localdb)\\mssqllocaldb; Database = afmil_Test_next; Trusted_Connection = True; "
                  );
  
          using (var context = new TestDbContext(optionsBuilder.Options))
          {
              var command = fixture.Create&lt;PostRegisterStudentCommand&gt;();
              var handler = new PostRegisterStudentCommandHandler(context);
  
              try
              {
                  handler.Handle(command);
              }
              catch (DbUpdateException e)
              {
                  var sb = new StringBuilder();
                  sb.AppendLine($"DbUpdateException error details - {e?.InnerException?.InnerException?.Message}");
  
                  foreach (var eve in e.Entries)
                  {
                      sb.AppendLine($"Entity of type {eve.Entity.GetType().Name} in state {eve.State} could not be updated");
                  }
  
                  sb.ShouldBeNull();
              }
  
              var dbStudent = context.Students.FirstOrDefault();
              dbStudent.ShouldNotBeNull();
              dbStudent.User.FirstName.ShouldBe(command.FirstName);
          }
  
      }
  </code></pre>
  
  <p>I got the exception catch part from an EF 6 stackoverflow <a href="https://stackoverflow.com/questions/22490842/finding-the-reason-for-dbupdateexception">answer</a>.</p>
  
  <p>I've search everything I can think of to find a example of extracting entity validation issues (DbEntityValidationException from EF6) in EF Core but cannot find anything that seems to work. </p>
  
  <p>As a suggestion from <a href="https://github.com/aspnet/EntityFramework/issues/3322" rel="nofollow noreferrer">this EF Core github issue</a>, I attempted to do some annotation validation like <a href="http://odetocode.com/Blogs/scott/archive/2011/06/29/manual-validation-with-data-annotations.aspx" rel="nofollow noreferrer">this</a>. But this didn't find the issues that the db was having with my student object.</p>