EF insert using SQL view suddenly giving optimistic concurrency error RRS feed

  • Question

  • 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

    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.
    Thursday, September 17, 2020 10:08 AM

All replies

  • You indicate  that your development machine was updated  and now you have a problem. I'll assume that the other developer's machine was not updated and code deployed from  that development machine does not have problems with the deployed code. 

    How is that your machine was updated? You should chalk it up  to lesson learned. There should be A standalone deployment machine and depolyments done from it and not from a  development machine . The deployment  machine  is kept in a pristuine state. Updates should by applied to the deployment machine after they have been tested a form of quality assurance.

    As for your development machine, you should restore it back to its prior state. 

    • Edited by DA924x Thursday, September 17, 2020 12:15 PM
    • Proposed as answer by Daniel Zhang-MSFT Friday, September 18, 2020 7:25 AM
    Thursday, September 17, 2020 12:11 PM