Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework Optimistic Concurrency with Update stored procedure (Julie Lerman example)
    primarykey
    data
    text
    <p>I'm having some difficulties understanding the Concurrency problem using Update store procedures. I'm following Julie Lerman's Programming Entity Framework and she gives the following code in an example:</p> <pre><code>using (var context = new BAEntities()) { var payment = context.Payments.First(); if (payment.PaymentDate != null) { payment.PaymentDate = payment.PaymentDate.Value.AddDays(1); } var origRowVersion = payment.RowVersion; try { //BREAKPOINT #1 context.SaveChanges(); var newRowVersion = payment.RowVersion; if (newRowVersion == origRowVersion) { Console.WriteLine("RowVersion not updated"); } else { Console.WriteLine("RowVersion updated"); } } catch (OptimisticConcurrencyException) { Console.WriteLine("Concurrency Exception was thrown"); } } </code></pre> <p>The Update SP looks like:</p> <pre><code>UPDATE payments SET paymentdate=@date,reservationID=@reservationID,amount=@amount, modifieddate=@modifiedDate WHERE paymentid=@paymentid AND ROWVERSION=@rowversion IF @@ROWCOUNT&gt;0 SELECT RowVersion AS newTimeStamp FROM payments WHERE paymentid=@paymentid </code></pre> <p>and the "Use original value" checkbox is ticked in the mapping, which looks like this: <a href="https://dl.dropboxusercontent.com/u/135754/updatemapping.png" rel="nofollow">https://dl.dropboxusercontent.com/u/135754/updatemapping.png</a> </p> <p>Now, when I try to:</p> <ol> <li><p>run the code as it is, then the newRowVersion inspected in the debugger is same as origRowversion, but the app enters 'else' clause (why is it the same in the first place, I have just changed it? is it debugger issue?)</p></li> <li><p>run the code, but in the BREAKPOINT #1 I update the payment object in Management Studio, the SaveChanges throws OptimisticConcurrencyException. I assume this is expected result.</p></li> </ol> <p>Each time when I look in the SQL Profiler, the original version of timestamp is sent to the server.</p> <p>Then, when I untick the "Use original value" in the SP mappings for the timestamp value, everything works the same way as described above... I don't get the idea of it. Am I testing it wrong? When is the app supposed to enter the 'if' clause?</p> <p>Thanks in advance, cheers!</p> <p>EDIT: I added newTimeStamp as the return value for the Update SP mapping. Now I can see that the updated value of RowVersion is correctly taken from the DB. But I still cannot see the difference between having "Use original value" checked and unchecked...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload