EF insert using SQL view suddenly giving optimistic concurrency error

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
DaveW
Posts: 6
Joined: Wed 17 Apr 2019 15:11

EF insert using SQL view suddenly giving optimistic concurrency error

Post by DaveW » Mon 14 Sep 2020 15:05

For the last few weeks I am seeing the following error in my development code whenever any insert using an SQL view happens in our code base -
"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions."
App is using EF6.2
My colleagues do not get the error using the exact same code (pull my feature branch and run it). We are using VS2019 and Devart’s Entity Developer.
This all started after updates to my development machine e.g. VS 16.7.1, ED 6.8.1049, etc.
Pseudo code which is failing

Code: Select all

context.<model class>.AddObject(model);
context.SaveChanges(); <= Error happens when this executes
The class maps through Entity Developer (model first) to a SQL view. This is an insert of a new object, NOT an edit of an existing one.
I know how to handle optimistic concurrency so please don't suggest ways to do that. The problem is that suddenly working code has stopped working.
I have tried, removing the updates which applied, also used a separate PC - a fresh Windows install, with older versions VS 16.6.5 and ED 6.8.1019 (also repeated using latest versions) and I still get the same error.
Error also follows if I deploy code (VS Publish) to a Cloud service but not if a colleague deploys the same code.
Any ideas are appreciated.

Shalex
Site Admin
Posts: 9077
Joined: Thu 14 Aug 2008 12:44

Re: EF insert using SQL view suddenly giving optimistic concurrency error

Post by Shalex » Tue 15 Sep 2020 15:19

Please specify "Found Rows=true;" in your connection string and try again. Refer to viewtopic.php?f=2&t=28529.

DaveW
Posts: 6
Joined: Wed 17 Apr 2019 15:11

Re: EF insert using SQL view suddenly giving optimistic concurrency error

Post by DaveW » Wed 16 Sep 2020 08:07

@Shalex Thanks for the reply, however isn't that only in MySQL? Never come across that one for MS SQL and so far can't find any reference to it anywhere.

Shalex
Site Admin
Posts: 9077
Joined: Thu 14 Aug 2008 12:44

Re: EF insert using SQL view suddenly giving optimistic concurrency error

Post by Shalex » Tue 22 Sep 2020 18:08

DaveW wrote:
Mon 14 Sep 2020 15:05
My colleagues do not get the error using the exact same code (pull my feature branch and run it).
DaveW wrote:
Mon 14 Sep 2020 15:05
Error also follows if I deploy code (VS Publish) to a Cloud service but not if a colleague deploys the same code.
We cannot explain the behavior you have encountered. Please try to localize the issue and send us a small test project with the corresponding DDL/DML script for reproducing.

DaveW
Posts: 6
Joined: Wed 17 Apr 2019 15:11

Re: EF insert using SQL view suddenly giving optimistic concurrency error

Post by DaveW » Wed 07 Oct 2020 09:22

After much testing I have identified the issue as being related to Entity Developer.

It appears that as long as the highest version number of ED I use is 6.7.965 then all is well. Any version newer than that (tested up to 6.9.1092) has the issue.

Luckily re-installing the older version, deleting the generated POCO's and regenerating them has worked.

Shalex
Site Admin
Posts: 9077
Joined: Thu 14 Aug 2008 12:44

Re: EF insert using SQL view suddenly giving optimistic concurrency error

Post by Shalex » Mon 12 Oct 2020 15:45

Please compare the code generated by v6.7.965 and v6.8.1019 to find out the exact change that leads to the issue.

Post Reply