Error is occurring after first data enter.

Error is occurring after first data enter.

Postby 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.
garbgdev
 
Posts: 13
Joined: Fri 08 Nov 2013 03:20

Re: Error is occurring after first data enter.

Postby 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/postgresql/docs/DbMonitor.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.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Error is occurring after first data enter.

Postby garbgdev » Mon 11 Nov 2013 20:03

Thanks, it works like charm
garbgdev
 
Posts: 13
Joined: Fri 08 Nov 2013 03:20


Return to dotConnect for PostgreSQL