views:

93

answers:

1

I'm trying to use Simple Savant within my application, to use SimpleDB

I currently have (for example)

public class Person
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public DateTime DateOfBirth { get; set; }
}

To use this with Simple Savant, i'd have to put attributes above the class declaration, and property - [DomainName("Person")] above the class, and [ItemName] above the Id property.

I have all my entities in a seperate assembly. I also have my Data access classes an a seperate assembly, and a class factory selects, based on config, the IRepository (in this case, IRepository

I want to be able to use my existing simple class - without having attributes on the properties etc.. In case I switch out of simple db, to something else - then I only need to create a different implementation of IRepository.

Should I create a "DTO" type class to map the two together?

Is there a better way?

+2  A: 

You should check out the Savant documentation on Typeless Operations. Typeless operations allow you to interact with Savant using dynamically constructed mappings rather than data/model objects. You could, for example, create a dynamic mapping for your Person class like this:

ItemMapping personMapping = ItemMapping.Create("Person", AttributeMapping.Create("Id", typeof (Guid)));
personMapping.AttributeMappings.Add(AttributeMapping.Create("Name", typeof (string)));
personMapping.AttributeMappings.Add(AttributeMapping.Create("Description", typeof(string)));
personMapping.AttributeMappings.Add(AttributeMapping.Create("DateOfBirth", typeof(DateTime)));

There are no functional restrictions when using this method because these ItemMappings are what Savant uses internally for all operations. It just takes a bit more work to understand and setup your mappings with this method.

Here's how you would retrieve a Person object using this method:

Guid personId = Guid.NewGuid();
PropertyValues values = savant.GetAttributes(personMapping, personId);
Person p = PropertyValues.CreateItem(personMapping, typeof(Person), values);
Ashley Tate