Domain methods - reflecting changes in domain context

Thread is closed for posting
2 posts, 0 answers
  1. Sambathraj
    Sambathraj avatar
    16 posts
    Member since:
    Jan 2011

    Posted 24 Jan 2014 Link to this post

    Most of the cases, I am handling the CRUD operations through domain methods. There is business logic within the stored procedures (just a preference)

    As soon as I call the domain method, the context starts a transaction and I am forced to call SaveChanges. But during updates, I get optimistic verification exception

    My sequence of call is

    1) Get the domain object from data context, make sure it is valid one. Update the values.

    2) Call the domain method by passing the required values

    3) Call save changes method.

    Insert and delete works fine. But update gives me optimistic verification since the record is updated by the stored procedure. 

    Please give me proper way of using stored procedures for CRUD operations. Basically, I want to use ORM for get and manage the CRUD separately using the domain methods. I also want the changes made in SP to be reflected in next get call in the ORM.

    What is the proper way to handle this?


  2. Jan Blessenohl
    Jan Blessenohl avatar
    707 posts

    Posted 27 Jan 2014 Link to this post

    Hello Sambat,

    At the end you are changing the data twice, once through changing them in the persistent object and second changing them with your SP. You should avoid doing it both, same is true for insert and update.

    After you have executed the SP and you have called SaveChanges or RollbackChanges OpenAccess makes sure that during the next read operation on your persistent objects the data is fetched from the server. Your workflow should be:

    1. Change data via stored procedure

    2. Call SaveChanges

    3. Read value from your persistent object and see that it contains the new data.


    Jan Blessenohl
    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
Back to Top