This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14748|Reply: 0

[Solved] Verification fails for one or more entities. For more information, see the EntityValidationErrors property.

[Copy link]
Posted on 10/8/2015 8:47:51 PM | | |
Because it is a reprint of the article The source is indicated here, please forgive me if there are articles that have been transferred before without indication, because some of them can no longer find the source, or for other reasons.

If you are offended, please contact me, or delete it, or indicate the source.

Because I used to just want to collect good articles, but sometimes the connection will fail, so now I go directly to myself when I encounter a good one.

Original source http://blog.csdn.net/snowinfish/article/details/11567301



When writing data to the ADO.NET entity model in VS2012, it keeps saying "DbEntityValidationException not handled" and "Validation of one or more entities failed. For more information, see EntityValidationErrors Properties.



Tested the next two entities myself, mainly the error caused by "operate911".

I checked the information online and referred to the following article.

Workaround for how to view EntityValidationErrors details

http://www.cnblogs.com/zhourq/archive/2011/11/03/2234720.html

However, when writing the exception, the system does not have "DbEntityValidationException", which is guessed to be a lack of namespace reference.

So added:

[csharp] view plaincopy
using System.Data.Validation;  

The corresponding procedure is modified to:
[csharp] view plaincopy
try  
{    entities. Operate911.Add(operate911);  
    entities. SaveChanges();  
}  
catch (DbEntityValidationException dbEx)   
{  

}  
Start, no exception prompt, "operate911" is not writing data to the database table.
The reason for checking is that when writing a supplementary program, there is no data filling for a column that is not allowed to be empty, and after modification, the program is started and the test is successful.



However, if you don't write an exception, continue to prompt the top error.

Moreover, the parameter "dbEx" after the sentence "catch (DbEntityValidationException dbEx)" can be written without writing.

Continue to be unknown...



09.12 Addendum:

The above try and catch are written incorrectly, and the exception is not thrown, but changed to:


[csharp] view plaincopy
try  
{      var operateSpt = new OperateSpt(ymd, timeNow, Operate);  
        entities. OperateSpts.Add(operateSpt);  
        entities. SaveChanges();  
}  

catch (DbEntityValidationException ex)  
{  
    MessageBox.Show(ex. Message);  
}  

The results are shown in the figure below.


Continue to be unknown...



Supplement: Problem solving.

Reason: The written data is inconsistent with the table settings.

My reason is that at a certain step, the written data is empty, but the original table is set to "not allowed to be empty", so there will be an exception when this step is performed.

I was too careless and never thought of this problem when I saw other operations written to the data when I was looking at the data.





Previous:Dianping and Meituan are going to merge for mutual benefit and win-win results.
Next:ASP.NET a collection of methods to get the root directory
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com