Modeling relationships

Aug 19, 2011 at 4:05 PM

I am trying to determine the best practice for modeling 1:M type relationship in Simol (and more specifically SimpleDB). 

Given a class 

Organization : Base

and a class

Member : Base

and a class 

Event : Base

I need to relate Organizations and Members and Events. I could have thousands of events for an organization, thousands of members for an organization, etc..

My current solution includes a property added on each class (though a Base class) called EntityRelationships. This property is a simple list of key/value pairs that includes the Type of the class being related and the id of the related entity. I serialize out the relationship using a formatter and end up with something like this:

List<NameValuePair> EntityRelationships 


I then store the EntityRelationship value with each class.

Anyone have any opinions on how this will handle thousands of relationships? Will I bump into an upper limit on attributes that the SpanAttribute can't handle and can I even use span with a custom formatter?

Would I be better suited with a separate EntityRelationship class for each relationship with the id of the parent mapped to the id of the child (seems like this would cause considerably more chatter, but could handle more relationships).

I really do appreaciate any feedback.





Aug 19, 2011 at 4:29 PM
Widescreen wrote:


 Will I bump into an upper limit on attributes that the SpanAttribute can't handle and can I even use span with a custom formatter?

Looking at it a little more closely, I guess I will run into a 256 attribute (or so, depending on the number of other attributes) limit. Any suggestions for getting around this? Is the better solution to hold the relationships in a separate domain?





Aug 19, 2011 at 9:34 PM

You can use SpanAttribute with a custom formatter, but not with lists unless you make Simol think the list is not a list by wrapping it in a class that does not implement IList or IEnumerable.

Think of it this way: SpanAttribute helps you spread a really big scalar property across multiple SDB attributes. List properties are automatically spread across multiple SDB attributes so you don't need SpanAttribute unless you want to format all the items in the list as one big blob.

With that approach you could store thousands of relationships but you wouldn't be able to search for relationships unless you turned on Simol full-text indexing for that field.

Aug 19, 2011 at 10:16 PM

Thanks, as always, Ashley. 

I think I've decided to move my relationships to their own domain. I figure I will take a slight performance hit, but I think that it will ultimately make things more flexible and future proof. 

Best regards,