I am using EF and npgsql with PostgreSQL. I have created views in PostgreSQL for access from my MVC project to PostgreSQL. All views have Return, Insert, Update and Delete rule.
The Return,Insert and Update work perfectly. My Delete rule is not a delete statement, but an Update statement which changes the status of the row to Inactive.
Therein lies the problem. The exception is thrown.
System.Data.Entity.Infrastructure.DbUpdateConcurrencyException
HResult=0x80131501 Message=Store update, insert, or delete statement affected an unexpected number of rows (0).
I dont think it is a concurrency problem, because I changed to view rule to a delete and the delete works.
EF with npgsql, expects a DELETE 1, where Postgresl returns an Update 1. Then an exception is thrown.
I could instruct the developers to issue and update statement instead and set the status to Inactive. But this is inelegant and requires sending the entire row to the database for an update.
Is there any way I can instruct npgsql, that a delete is actually an update.
my code: exception thrown on db.SaveChanges();
public static void RemoveAppointment(clinic_time_blocks appt)
{
Entities db = new Entities();
clinic_time_blocks query = (clinic_time_blocks)db.clinic_time_blocks.Where(e => e.clinic_time_blocks_id == appt.clinic_time_blocks_id).FirstOrDefault();
db.clinic_time_blocks.Remove(query);
db.SaveChanges();
}
Thank you
Bob
User contributions licensed under CC BY-SA 3.0