Self Tracking Entities in Entity Framework fails to update if orignial value is NULL - by Rune Gulbrandsen

Status : 

  External<br /><br />
		This item may be valid but belongs to an external system out of the direct control of this product team.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 659743 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 4/12/2011 12:37:08 AM
Access Restriction Public


Discovered a bug in the Self-Tracking Entity Generator Template yesterday while working with the modification suggested by Jeff Derstadt in the blog article

Now I have finally after a bit of debugging found the problem, which seems to be a bug in the template (And maybe in fact in the framework?).

The problem is that the SetValue function does a check against the clr type of the property if it is a Nullable type or not and if it isn't Nullable setting the original value won't happen. For some reason this check fails, even if my column is Nullable (which the EdmProperty.Nullable states) and the code fails to update my changes to the database.

If I try to change this code to check against EdmProperty.Nullable instead, the code fails with an exception in OriginalValueRecord.SetValue instead (which uses the same rules).

Sign in to post a comment.
Posted by dotcomsoftware on 6/29/2012 at 3:30 AM
Please note that this bug affects EF POCO objects as well, not just Self-Tracking entitites. See: for details
Posted by Microsoft on 10/14/2011 at 4:00 PM
Hello Rune,

A fix will be included in .NET 4.5 that will remove the limitation for handling null original values for both Self-Tracking Entities and the Entity Framework runtime.

In the meanwhile the only workaround I know of is to ensure that the properties for which we need to track original values in Self-Tracking Entities (i.e. they are marked for concurrency control or are part of foreign keys) never has a null value. This could be done in a number of ways:
-    Set a default value of zero or -1 (or some other unused value) in the constructor for the entity. This might not work if the database already contains rows with null values.
-    Stop using a column the property’s original value for concurrency control and switch to other properties or add a Timestamp property with that goal.

Thanks a lot for raising this issue!
Diego Vega
Entity Framework Team
Posted by Microsoft on 4/12/2011 at 2:29 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 4/12/2011 at 1:14 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(
Posted by Rune Gulbrandsen on 4/12/2011 at 12:42 AM
Workarond for the problem posted which helped me.