Error is occurring after first data enter.

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
garbgdev
Posts: 13
Joined: Fri 08 Nov 2013 03:20

Error is occurring after first data enter.

Post by garbgdev » Sun 10 Nov 2013 21:57

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.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Error is occurring after first data enter.

Post by MariiaI » Mon 11 Nov 2013 15:01

Devart.Data.PostgreSql.PgSqlException: duplicate key value violates unique constraint
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.
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.

garbgdev
Posts: 13
Joined: Fri 08 Nov 2013 03:20

Re: Error is occurring after first data enter.

Post by garbgdev » Mon 11 Nov 2013 20:03

Thanks, it works like charm

Post Reply