Hi I made a simple database trough devart entity developer and generate model in Visual studio. I wanted to have a test simple query, I added a controller to my model(MVC controller write/delete with entity framework). My first attempt to create a new row to database worked fine but error is occurring from the second data entering(DbUpdateException). And also delete does not work for the existing data.
Line 108: Organisation organisation = db.Organisations.Find(id);
Line 109: db.Organisations.Remove(organisation);
Line 110: db.SaveChanges();
Line 111: return RedirectToAction("Index");
Devart.Data.PostgreSql.PgSqlException: duplicate key value violates unique constraint
Error is occurring at line 110. Please help me.
Error is occurring after first data enter.
Re: Error is occurring after first data enter.
Such an error on the second data insertion can occur in case when you have an autoincrement primary key in the database table, and the Store Generated property is not set to Identity for the corresponding entity property in the SSDL part of you model.Devart.Data.PostgreSql.PgSqlException: duplicate key value violates unique constraint
Please check it:
- open your model and select the necessary entity class;
- select its entity key( e.g., "Id") and open its "Property Editor" by double-clicking it;
- check that the Store Generated property is set to Identity;
- open the "Storage Column Editor" for the "Id" property and set the "Stored Generated" to Identity too;
Also, you could check the generated SQL scripts: http://www.devart.com/dotconnect/postgr ... nitor.html
If it doesn't help, please send us a sample project with the model so that we are able to investigate this issue in more details and find a solution for you.
Re: Error is occurring after first data enter.
Thanks, it works like charm