Search code examples
.netsqliteentity-framework-corerepository-patternunit-of-work

EFCore with SQLite shows concurrency exception


I am using EFCore in .Net Core project with db as SQLite. When i try to add a row to a table I am getting "Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. unit of work"

When I change from SQLite to SQLServer, everything works fine.

My entity has an ID property which is the Primary Key. I tried adding [DatabaseGenerated(DatabaseGeneratedOption.Identity)] attribute and without it. Still getting same error. But when i tried by entering the Id value along with rest of data, the insertion works. Could someone throw some light into this issue. Why am i getting this error only for SQLite.


Solution

  • The entity had a user-defined property called RowId which conflicted with the default RowId of SQLite. I renamed this user-defined property and I was able to resolve this issue.