storing objects with relationships

Sep 14, 2010 at 6:40 PM

I have an object called "product" that has a "ParentArea" property on it. 

I am unable to save when the "parentArea" is null. I have made sure that "Area" class has a parameterless constructor.

I get "There was an error reflecting type".

what is the guidance when it comes to storing objects with relationships?

Also, when I tried to save an object with a "Uri" property, the "Save" failed.




Sep 15, 2010 at 1:11 AM

I do not think saving Parent with a child will work.  Think of it as DB - in DB you have to save ID and have another table for parent.  So, you should have two tables in DB - Areas and Products.  Products will have AreaID property in it.  Then you can use Linq to join them together in your UI.

As far as Uri goes, I think you will have to save it as string instead.  I.e. make your property string instead of Uri , and convert to Uri using a ValueConverter  or in code.


Thanks.  Hope this helps.


Sep 15, 2010 at 2:30 AM


Thanks for the response. I dug a bit deeper and realized that the if domain object cannot be serialized cannot be persisted. Parent and child cannot point to each other.

Is there a way to use attributes in order to facilitate ignoring of some properties for persistence?

e.g. I can have 2 properties, one Uri and one string representation of the Uri, but ignore the Uri property for persistence.






Sep 15, 2010 at 3:24 AM

XmlSerializer that I use will serialize all public properties, thus you cannot really ignore any of them.  So, unfortunately, you are probably stuck using converters.


Oct 15, 2010 at 4:10 PM

I have not used your library (yet)... but the regular XmlSerializer will ignore all properties marked as [XmlIgnore]... that might do the trick for you.

Oct 15, 2010 at 5:47 PM

Good suggestion.  Thanks.