Skip to content
scale-tone edited this page Apr 16, 2017 · 3 revisions

Here you have three options.

1. Most common and unobtrusive way is to just define a POCO object:

public class Movie
{
    public string Genre { get; set; }
    public string Title { get; set; }
    public string Director { get; set; }
    public int Year { get; set; }
    // other fields...
}

Though, this might be not the most efficient way, because the change tracking mechanism used in this case is the same as used in Entity Framework: all loaded entities (not only modified ones) are serialized and compared upon submit.

2. To enable using AWSSDK Document's change tracking mechanism, you need to derive from EntityBase class:

public class Reviewer : EntityBase
{
    public string Login { get; set; }
    public string Password { get; set; }
    // other fields...
}

In this case, no actual objects will be created and TransparentProxies around AWSSDK Documents will be used instead.

3. If you're not planning to add new entities to an existing table, then it's enough to define an interface:

public interface Genre
{
    string Title { get; set; }
    string DescUrl { get; set; }
    // other fields...
}

For entity properties the same set of primitive data types and collections (List<T>, ArrayList etc.) as in Amazon.DynamoDB.DataModel is supported. Plus: you can use arrays:

public int[]() ArrayField { get; set; }

Starting from version 1.4.2, complex types and lists of complex types:

public class Studio
{
    public string Title { get; set; }
    public string Address { get; set; }
}

public class Actor
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

public class Movie
{
    ....
    public Studio DistributedBy { get; set; }
    public List<Actor> Starring { get; set; }
}

are also supported. Please, note though, that change tracking inside complex objects works only in unobtrusive mode.

And for other complex types you can still declaratively specify an IPropertyConverter implementation:

[DynamoDBProperty(typeof(StringTimeSpanDictionaryConverter))]
public IDictionary<string, TimeSpan> FilmsBasedOnBook { get; set; }

To prevent some property from being saved to DynamoDB mark it with DynamoDBIgnoreAttribute:

[DynamoDBIgnore]
public string IgnoredField { get { return "123"; } }

The important thing now is how DataContext maps entities to tables in DynamoDB. That is, how to specify a table name for your entity. Here is how.

NOTE: you don't need to declaratively specify, which of the fields is a HashKey, which of the fields is a RangeKey etc. LINQ2DynamoDB is clever enough to discover that from the table's description loaded from DynamoDB.