title: System.Data.Entity.Validation.DbEntityValidationException
body: <p>I have a project that uses Entity Framework. While calling SaveChanges on my DbEntityValidationException, I get the following exception:</p>
  
  <blockquote>
    <p>System.Data.Entity.Validation.DbEntityValidationException: 'Validation
    failed for one or more entities. See 'EntityValidationErrors' property
    for more details.'</p>
  </blockquote>
  
  <p>This is all fine and dandy, but I don't want to attach a debugger every time this exception occurs. More over, in production environments I cannot easily attach a debugger so I have to go to great lengths to reproduce these errors. </p>
  
  <p>How can I see the details hidden within the DbEntityValidationException?</p>
  
  <p><a href="https://i.stack.imgur.com/BdnQL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BdnQL.png" alt="DbEntityValidationException"></a></p>
  
  <pre><code>private void btnCreateLetter_Click(object sender, EventArgs e)
  {
  
      using (TransactionScope TS = new TransactionScope())
      {
          try
          {
              Letter TblLetter = new Letter();
              TblLetter.Subject = txtSubject.Text.Trim();
              TblLetter.Abstract = txtAbstract.Text.Trim();
              TblLetter.Body = ckeCKEditor.TextEditor.Text.Trim();
              {
                  var LastLetterID = (from Letter in Database.Letters orderby Letter.LetterID descending select Letter).First();
                  TblLetter.LetterNO = PublicVariable.TodayDate.Substring(0, 4).Substring(2, 2) + PublicVariable.gDetermineJobLevel + "/" + (LastLetterID.LetterID + 1);
              }
              TblLetter.CreateDate = lblCreateDate.Text;
              TblLetter.UserID = PublicVariable.gUserID;
              if (rdbClassification.Checked == true)
              {
                  TblLetter.SecurityType = 1;
              }
              else if (rdbConfidential.Checked == true)
              {
                  TblLetter.SecurityType = 2;
              }
              else if (rdbSeries.Checked == true)
              {
                  TblLetter.SecurityType = 3;
              }
              if (rdbActionType.Checked == true)
              {
                  TblLetter.UrgencyType = 1;
              }
              else if (rdbInstantaneous.Checked == true)
              {
                  TblLetter.UrgencyType = 2;
              }
              else if (rdbAnnie.Checked == true)
              {
                  TblLetter.UrgencyType = 3;
              }
              TblLetter.ArchivesType = 1;
              if (rdbFollowHas.Checked == true)
              {
                  TblLetter.FollowType = 1;
              }
              else if (rdbFollowHasnoot.Checked == true)
              {
                  TblLetter.FollowType = 2;
              }
              if (rdbAttachmentHas.Checked == true)
              {
                  TblLetter.AttachmentType = 1;
              }
              else if (rdbAttachmentHasnot.Checked == true)
              {
                  TblLetter.AttachmentType = 2;
              }
              TblLetter.ReadType = 1;
              TblLetter.LetterType = 1;
              TblLetter.DraftType = 1;
  
              if (rdbResponseDeadlineHas.Checked == true)
              {
                  TblLetter.AnswerType = 1;
                  TblLetter.AnswerReadLine = String.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(pdpSetResponseDeadline.Value.Year.ToString() +
                      "/" + pdpSetResponseDeadline.Value.Month.ToString() + "/" + pdpSetResponseDeadline.Value.Day.ToString()));
              }
              else if (rdbResponseDeadlineHasnot.Checked == true)
              {
                  TblLetter.AnswerType = 2;
              }
              Database.Letters.Add(TblLetter);
              Database.SaveChanges();
              if (rdbAttachmentHas.Checked == true)
              {
                  if (lblPath.Text != "")
                  {
                      FileStream ObjectFileStream = new FileStream(lblPath.Text, FileMode.Open, FileAccess.Read);
                      int Lenght = Convert.ToInt32(ObjectFileStream.Length);
                      byte[] ObjectData;
                      ObjectData = new byte[Lenght];
                      string[] strPath = lblPath.Text.Split(Convert.ToChar(@"\"));
                      ObjectFileStream.Read(ObjectData, 0, Lenght);
                      ObjectFileStream.Close();
  
                      AttachFile TableAttachFile = new AttachFile();
                      TableAttachFile.FileSize = Lenght / 1024;
                      TableAttachFile.FileName = strPath[strPath.Length - 1];
                      TableAttachFile.FileData = ObjectData;
                      TableAttachFile.LetterID = TblLetter.LetterID;
                      Database.AttachFiles.Add(TableAttachFile);
                      Database.SaveChanges();
                  }
              }
              TS.Complete();
              MessageBox.Show("saved", "ok", MessageBoxButtons.OK, MessageBoxIcon.Information);
          }
          catch (InvalidCastException ex)
          {
              MessageBox.Show(ex.ToString());
              MessageBoxIcon.Error);
              return;
          }
      }
  }
  </code></pre>