New Posts New Posts RSS Feed: 'Non-native' DataEntityProperties not getting default values initialized
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

'Non-native' DataEntityProperties not getting default values initialized

 Post Reply Post Reply
Author
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Topic: 'Non-native' DataEntityProperties not getting default values initialized
    Posted: 22-Mar-2012 at 4:43pm
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
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 27-Mar-2012 at 10:00am
Hi Stephen,
 
Could you provide a solution reproducing the issue. (Against NorthwindIB if possible, please)
 
Regards,
   Silvio.
Back to Top
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Posted: 27-Mar-2012 at 11:06am
I was able to reproduce the problem easily with the "Simple console app (Silverlight)" code sample.  All I did was make a partial class for Customer and try to add a new DataEntityProperty that isn't database backed.  The code looks like this:
using System.Runtime.Serialization;
using IdeaBlade.EntityModel;

namespace SilverlightConsole
{
    public partial class Customer
    {
        [DataMember]
        public bool MyExtraProp
        {
            get { return PropertyMetadata.MyExtraProp.GetValue(this); }
            set { PropertyMetadata.MyExtraProp.SetValue(this, value); }
        }

        public new partial class EntityPropertyNames
        {
            public const string MyExtraProp = "MyExtraProp";
        }

        public partial class PropertyMetadata
        {
            public static readonly DataEntityProperty<Customer, bool> MyExtraProp =
                new DataEntityProperty<Customer, bool>(propertyName: EntityPropertyNames.MyExtraProp,
                                                       isNullable: false,
                                                       isPartOfKey: false,
                                                       concurrencyStrategy: ConcurrencyStrategy.None,
                                                       isAutoIncrementing: false,
                                                       relatedNavigationPropertyName: null,
                                                       isNativeProperty: false);
        }
    }
}

With that change, any requests to load Customers will fail.  The 'getter' of MyExtraProp (that gets called during serialization I believe) will throw the NullReferenceException I originally reported.

I've also attached the entire solution.  All you need to do is run it and the server will throw the exception.  Let me know if you need anything else to reproduce it.   

Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 28-Mar-2012 at 3:00pm
Thanks Stephen,
 
We are investigating the issue.
 
Silvio.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 30-Mar-2012 at 10:31am
Hi Stephen,
 
This was indeed a bug and has already been fixed.
 
The fix will be available in DevForce 6.1.7.
 
Regards,
   Silvio.
Back to Top
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Posted: 22-Jan-2014 at 4:23pm
I have same issue with DataEntityProperty. I am using 6.1.16
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 06-Feb-2014 at 11:52am
Hi hijaggu,

Our tests for the above bug report still pass for 6.1.16. You may have a slightly different scenario. Could you attach a reproducible solution so we may be able to investigate further?
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down