none
Concurrency and new data RRS feed

  • Question

  • Hi,

    we have 2 threads with 2 different contexts. In one thread we delete and add new entities and in the other thread we delete some entities. In the 2° thread we get concurrency errors because some times in the first thread we delete entities. So the problem is how can we refresh the context in the second thread so it loads newly added data to the DB from the first thread so subsequently delete them?

    Thanks in advance.


    Bilhan silva

    Tuesday, March 27, 2012 9:31 AM

Answers

  • Hi Centigradz,

    Welcome to MSDN Forum.

    Does your database tables have timestamp or rowversion column to detect concurrency? If the tables have, you can use ObjectContext.Refresh method to handle the concurrency. This method can help you to replace the value of the entities as datasource value or modified value. More information about it, please refer to the link.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Centigradz Wednesday, April 4, 2012 9:08 AM
    Monday, April 2, 2012 6:33 AM
    Moderator

All replies

  • Use Local.

    Fighting like Allen Iverson. Neve give up!

    Tuesday, March 27, 2012 4:50 PM
  • Hi Hero,

    this doesn't help as i have a table with a large quantity of data i can't load it all in memory. and the thread with datacontext could be in another applicatation context so how can i sincronize these two?


    Bilhan silva

    Wednesday, March 28, 2012 7:49 AM
  • Does this help?

    http://msdn.microsoft.com/nb-no/sync/bb887608%28en-us%29.aspx

    I also find some similar threads

    http://stackoverflow.com/questions/3889345/entity-framework-and-synchronizing-a-database-solution

    http://stackoverflow.com/questions/3928873/synchronize-records-using-entity-framework


    Fighting like Allen Iverson. Neve give up!

    Thursday, March 29, 2012 3:07 AM
  • Hi,

    It's too difficult to implement and we can't change our applications architecture in this moment. Is there any way to say to the entity context to refresh it's cache and reload data from DB?


    Bilhan silva

    Friday, March 30, 2012 12:21 PM
  • Hi Centigradz,

    Welcome to MSDN Forum.

    Does your database tables have timestamp or rowversion column to detect concurrency? If the tables have, you can use ObjectContext.Refresh method to handle the concurrency. This method can help you to replace the value of the entities as datasource value or modified value. More information about it, please refer to the link.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Centigradz Wednesday, April 4, 2012 9:08 AM
    Monday, April 2, 2012 6:33 AM
    Moderator
  • Hi,

    sorry for the late response. this seems to work. thanks


    Bilhan silva

    Wednesday, April 4, 2012 9:08 AM