This is a migrated thread and some comments may be shown as answers.

Domain methods - reflecting changes in domain context

1 Answer 44 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sambathraj
Top achievements
Rank 1
Sambathraj asked on 24 Jan 2014, 05:47 PM

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?



Sambath.




1 Answer, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 27 Jan 2014, 02:40 PM

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.



Regards,

Jan Blessenohl
Telerik
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!
Tags
Development (API, general questions)
Asked by
Sambathraj
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Share this question
or