Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq to Sql: ChangeConflictException not being thrown (and no rows updated/deleted)
    primarykey
    data
    text
    <p>I'm trying to fit Linq to Sql into an N-Tier design. I am implementing concurrency by supplying original values when attaching objects to the data-context. When calling SubmitChanges, and observing the generated scripts on sql server profiler, I can see that they are being generated properly. They include where clauses that check all the object properties (they are all marked with UpdateCheck.Always).</p> <p>The result is as expected, i.e., no rows are updated on updates or deleted on deletes. Yet I am not getting any exception. Isn't this supposed to throw a ChangeConflictException?</p> <p>For clarity here is the design and flow for the tests I'm running: I have a client console and a service console talking to each other via WCF using WsHttpBinding.</p> <ol> <li>Client requests data from service </li> <li>Service instantiates a datacontext, retrieves data, disposes context, returns data to client. </li> <li>Client makes modifications to returned data. </li> <li>Client requests an update of changed data from the service.<br> 5a. Service instantiates a datacontext, attaches objects, and...<br> 5b. I pause execution and change values in the database in order to cause a change-conflict<br> 5c. Service calls SubmitChanges. </li> </ol> <p>Here's the code for step 5, cleaned up a bit for clarity:</p> <pre><code>public void UpdateEntities(ReadOnlyChangeSet&lt;Entity&gt; changeSet) { using (EntityDataContext context = new EntityDataContext()) { if (changeSet.AddedEntities.Count &gt; 0) { context.Entities.InsertAllOnSubmit(changeSet.AddedEntities); } if (changeSet.RemovedEntities.Count &gt; 0) { context.Entities.AttachAll(changeSet.RemovedEntities, false); context.Entities.DeleteAllOnSubmit(changeSet.RemovedEntities); } if (changeSet.ModifiedRecords.Count &gt; 0) { foreach (var record in changeSet.ModifiedRecords) { context.Entities.Attach(record.Current, record.Original); } } // This is where I pause execution and make changes to the database context.SubmitChanges(); } } </code></pre> <p>I'm using some classes to track changes and maintain originals, as you can see.</p> <p>Any help appreciated.</p> <p>EDIT: I'm having no problems with inserts. I've only included the code that calls InsertAllOnSubmit for completeness.</p>
    singulars
    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.
 

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