Modeling relationships

Aug 19, 2011 at 3: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
Id
Name
Address
Phone


and a class

Member : Base
Id
FirstName
LastName
Address
Phone

and a class 

Event : Base
Id
Name
StartDate
EndDate
 

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:

Base
List<NameValuePair> EntityRelationships 

{"Key":"51da7ad9-96ff-4299-8030-d99db979865d","Value":"Contact"}

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.

Sincerely,

Hal

 

 

Aug 19, 2011 at 3: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?

 

Thanks,

 

Hal

Coordinator
Aug 19, 2011 at 8: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 9: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,

Hal