As part of an upgrade from 6.1.3.1 to 6.1.6.0, we've started getting some NullReferenceExceptions when doing queries for certain entities. I tracked it down to entities which we've added extra DataEntityProperties by doing something like this:
public partial class PropertyMetadata { public static readonly DataEntityProperty<MyEntity, bool> ExtraProperty = new DataEntityProperty<MyEntity, bool>(EntityPropertyNames.ExtraProperty, false, false, ConcurrencyStrategy.None, false, null, false); } |
During deserialization, the 'get' of this property (which is marked with [DataContract]) throws the NRE in DataEntityProperty<,>.GetValue(TInstance, EntityVersion). The DevForce code is like this:
return (TValue) obj2.GetValueRaw(this, EntityVersion.Current); |
The GetValueRaw returns NULL but then it tries to cast to TValue which is bool in my case. In debugging this, I see that the way default values get set seems to have changed so I'm thinking this is probably related to that change.
If I create an instance of my entity in memory, the property works fine....for example:
var myEntity = new MyEntity();var x = myEntity.ExtraProperty; //Does not throw an exception |
But I think the default values don't get set up when an entity is being materialized as part of a query from the database? I'm not entirely sure but I do know that my code is breaking now. I also tried creating the DataEntityProperty by passing 'true' as the last parameter (isNativeProperty) but that didn't seem to help - I never quite understood what that parameter was for but I thought I might as well try it.
Is this a bug? Or is there some other way I should be declaring extra, non-DB backed DataEntityProperties?
Thanks,
-Stephen