Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq2Sql creates an extra instance when I change the value of a property - why?
    primarykey
    data
    text
    <p>I have a table called UserProperties. There is a small set of user properties for each user. I load them up into the program into a Dictionary called <strong>_userProperties</strong> (so that they are cashed).</p> <p>Basicly the table looks like this:</p> <p><img src="https://i.stack.imgur.com/QjB5H.jpg" alt="User Properties Table"></p> <p>The columns: CreatedOn, ModifiedOn, CreatedBy and ModifiedBy are not part of the DAL (dbml) as they are strictly for debugging purpuses. A trigger sets ModifiedBy and ModifiedOn.</p> <p>When the user wants to save his settings (or the program thinks they should be saved) I call this code:</p> <pre><code> string userPropertyValueAsString = (String)Convert.ChangeType(userPropertyValue, typeof(String)); if (_userProperties.ContainsKey(userPropertyKey)) { if (_userProperties[userPropertyKey] != userPropertyValueAsString) { using (DataAccessDataContext dataContext = CreateContext(JsApplication.CommitDal)) { (1) UserProperty changedUserProperty = dataContext.UserProperties.First(u =&gt; u.fk_Employee == employeeId &amp;&amp; u.PropertyName == userPropertyKey); (2) changedUserProperty.PropertyValue = userPropertyValueAsString; _userProperties[userPropertyKey] = changedUserProperty.PropertyValue; if (!dataContext.SubmitChanges()) { throw new SubmitChangesException(employeeId); } } } } </code></pre> <p>When I reach (1) the constructor of class UserProperty gets called (as expected since a UserProperty is found in the table at the database). But when I reach (2) the constructor is called again, which creates a second instance and this has me baffled.</p> <p>No exception gets thrown and the extra instance gets saved to the table (which cause a bug because the extra instance contains the changes propertyvalue and the next time the old value gets read from the database through the row with the smaller id (the old one)).</p> <p>The callstack looks like this (I put a breakpoint into the constructor and captured the screendumb right after (2):</p> <p><img src="https://i.stack.imgur.com/8rScz.jpg" alt="Call stack just after (2)"></p> <p><strong>Could anyone please tell me why WPF does this and how I make it stop?</strong></p> <p>Windows: Windows 7 Ultimate 64 bit Visual Studio: Visual Studio 2010 Ultimate</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.
 

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