November Happy Hour will be moved to Thursday December 5th.

Possible error in Dynamic Data Store when using inheritance

Vote:
 

I believe I have discovered a bug with the Dynamic Data Store when using inheritance.
In the documentation it says that in order to save a property in the Dynamic Data Store, the property must be public and have a setter (which can be non-public). Properties without setters are ignored. For instance, in the following object, MyProperty will be added in the Dynamic Data Store but MyGetterProperty will not:

public class MyData : IDynamicData
{
public Identity Id { get; set; }
public int MyProperty { get; set; }

public int MyGetterProperty {
get { return MyProperty + 2; }
}
}

This is working as you would expect. However, consider this example where I instead implement MyGetterProperty in a abstract base class:

public abstract class MyData : MyDataBase, IDynamicData
{
public Identity Id { get; set; }
public override int MyProperty { get; set; }
}

public class MyDataBase
{
public abstract int MyProperty { get; set; }

public int MyGetterProperty {
get { return MyProperty + 2; }
}
}

In this example, if I save an object of MyData to the Dynamic Data Store, MyGetterProperty now gets included in the database! When I try to read an object from the store I get an error in DereferencedPropertyBag.ToClonedObject saying that the property cannot be written because no setter was available. The error is that the getter property from the base class gets included in the Dynamic Data Store.

Am I correct in assuming that this is a bug? Is there a workaround to the problem or am I perhaps doing something wrong?

#122878
Jun 17, 2015 9:38
Vote:
 

Whoops, MyDataBase should be abstract in the last code sample, not MyData.

#122879
Jun 17, 2015 9:42
Vote:
 

The workaround is to use DataContract, and DataMember on the class and properties.

#123393
Jul 03, 2015 8:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.