Storing a Dictionary in SimpleDB using SimpleSavant

Feb 25, 2010 at 11:20 PM


I'm trying to store the following property

public List<Dictionary<string, Guid>, string> Files { get; set; }

Basically, the dictionary is a string, guid pair of storage mechanism, identifier, and the string is a friendly filename.

Is this possible?

I've tried this so far, but nothing get's stored against the inserted item

Feb 26, 2010 at 12:45 AM

OK, first it looks like bit of a syntax error in your code snippet. You are storing a list of Dictionaries, right?


public List<Dictionary<string, Guid>> Files { get; set; }


Mapping and formatting rules are documented here: Defining Object Mappings

Your property is only mapped automatically if it is a default property type or a generic collection containing one of the default property types. A Dictionary is not one of the default mapped types (all value types plus string are mapped by default) so you'll need to mark this property with some Savant attribute for it to be included in your mapping. Since Savant doesn't know how to serialize your dictionary instances into scalar string values, the property must be marked with a CustomFormatAttribute, that references an implementation of ITypeFormatter. Basically, each item in your list gets stored in a single SimpleDB attribute value.

Feb 26, 2010 at 2:14 PM

You're right, there was a syntax error in that.
Also, I don't think a dictionary is quite right for my requirements.

Basically, I need to store 3 values per "attachment"

1) The Storage mechanism (string)
2) The Storage Identifier (object - could be either string or Guid- for example, Guid if file is stored in S3, string, if it's a filesystem) - i know SimpleDB only stores strings
3) Friendly name - "myFile.doc" for example

I've created a class, called "SentMailAttachment" - that looks like this:

    public class SentEmailAttachment
        public string StorageService { get; set; }
        public object StorageID { get; set; }
        public string FileName { get; set; }

My SentMail class now has a List<SentEmailAttachment> property
How can i store a list of these 3 properties alongside my SentMail item?

So it has attributes like:


  [StorageService='S3'', StorageID-'KWJWER-WERKJ34-345RSDF-234R3', FileName='myFile.doc']
  [StorageService='S3'', StorageID-'KgJWER-WERKJ34-3RasSDF-234R3', FileName='myFile2.doc']
  [StorageService='S3'', StorageID-'KWJWER-WERKJ34-345RSDF-234R3', FileName='myFile3.doc']
  [StorageService='S3'', StorageID-'KJWgfy-WERKJ34-345RSDF-234R3', FileName='myFile4.doc']

Feb 26, 2010 at 9:06 PM

Without getting too exotic you have these choices:

  1. Jam your 3 attachment properties into a single attribute value (concatenate the 3 strings). This would let you store up to 256 attachments associated with a single message in your mail Email domain, but you would still need to define a custom formatter for your SentMailAttachment.
  2. Store your attachment items in a separate domain and associate them with your email items by storing the attachment ids in the email domain.

Honestly, it sounds like you need to back up a bit and decide on your SimpleDB data structure before worrying about how to encode/decode your items into objects. There lots of folks over on the Amazon SimpleDB forum who love to help with that sort of thing.

After you settle on your basic structure I can give you better advice about how to make it work with Savant. Savant doesn't do any relationship or association management automatically yet, but I'm considering some options in that area and would love to hear your feedback once you work through your design.