Skip to content

Deriving from DataContext

scale-tone edited this page Apr 16, 2017 · 2 revisions

A data context in your project will usually be designed as a child of DataContext with specific properties representing your tables:

public class ReviewsDataContext : DataContext
{
    private static readonly IAmazonDynamoDB DynamoDbClient;

    static ReviewsDataContext()
    {
        string accessKey, secretKey;
        GetAwsCredentials(out accessKey, out secretKey);
        DynamoDbClient = new AmazonDynamoDBClient(accessKey, secretKey);
    }

    public ReviewsDataContext() 
        : 
        base(DynamoDbClient, GetTableNamePrefixFromConfig())
    {
    }

    public DataTable<Movie> Movies { get { return this.GetTable<Movie>(); } }
    public DataTable<Review> Reviews { get { return this.GetTable<Review>(); } }
    // other tables...

}