Domain Partitioning - How to store the same item type across multiple SimpleDB domains?

Nov 3, 2010 at 7:43 PM

Thanks for writing Simple Savant.  I'm just getting started with in in the last few weeks and I have encountered a scenario where I need to store the same class/type in multiple domains.  In the documentation it mentions that this can be accomplished with a typeless operation and I wanted to ask if there is an example that could be provided of a scenario like the one below.

"Domain partitioning - If your application needs to partition data for the same item type across multiple SimpleDB domains you can use typeless operations to change domain names on the fly, rather than being restricted to one static domain per persistent type."

Scenario:  Depending on the value of a function (gets the day of the week as an integer), a Person object needs to either be stored in a different SimpleDB Domain named person-{0} (where {0} is replaced with the day number, e.g. person-1).

Thank you so much for helping and giving back to the developer community,

Nov 3, 2010 at 9:21 PM

You're welcome!

Here's an example of what you're attempting. Just create a PropertyValues collection from your data object, create a TypeMapping from your data class, change the domain name on the mapping, and put the values collection into SimpleDB:

public class Person
	public Person()
		Id = Guid.NewGuid();

	public string Name { get; set; }

	public Guid Id { get; set; }

var savant = new SimpleSavant(awsAccessKeyId, awsSecretAccessKey);

var person = new Person();
var values = PropertyValues.CreateValues(person);
var mapping = ItemMapping.Create(typeof (Person));
mapping.DomainName = "Person-" + (int)DateTime.Today.DayOfWeek;
savant.PutAttributes(mapping, values);