MVC, using EF to build entities. The data is stored in the database and executed to _db. SaveChange (), the following error is reported:
In the database data storage, often encounter this problem, the cause of this error is a variety of Internet search solutions, as follows:
1. There is said to set the null option to "can be empty", but I This "ID" field is the primary key, how can be set to be empty? Veto
2. Say that the identity specification is set to "yes", such as, however, that the identity specification is selected as "Yes" is to add the self-increment function to the field, which should require that the field type is integer? My field type is "Guid" and cannot modify the identity specification to "yes", so the second solution can't solve my problem, veto
On the internet basically these two solutions, can not solve the problem, eh, still have to find their own slowly, finally:
Workaround:
First step: Open the. edmx file, select the field that is faulted, and in the property box on the right, set StoreGeneratedPattern to "None", such as:
Step Two: Right-click the table view in the. edmx file, select Generate database from model, as follows
Step Three: Fool operation, no tube, direct point "complete" is "yes"
Fourth step: Run the program, problem solving, haha!
You cannot insert a value of NULL into the column ' ID ', table ' EupStoreDemoDB.dbo.OrderDiary ', and the column does not allow null values. INSERT failed.