-
Notifications
You must be signed in to change notification settings - Fork 23
Specifying table name for an entity
By default,
: tableName = tableNamePrefix + typeof(MyEntity).Name , where tableNamePrefix is the parameter passed to DataContext's constructor.
You can override this with DynamoDBTableAttribute:
[DynamoDBTable("Genres")]
public class Genre : EntityBase
{
...
}
Unfortunately, DynamoDBTableAttribute cannot be put on an interface. So, if you're defining your entity as an interface, then your last option is to use the GetTable<TEntity>() method, that takes a Table instance as a parameter:
private static Table _reviewersTable;
public DataTable<Reviewer> Reviewers
{
get
{
if (_reviewersTable == null)
{
_reviewersTable = Table.LoadTable(DynamoDbClient, "Reviewers");
}
return this.GetTable<Reviewer>(string.Empty, null, _reviewersTable);
}
}
NOTE: Table.LoadTable() method takes some time, because it gets the table description from DynamoDB (makes a heavy request). This is why Table objects are cached in a static variable inside DataContext. So, if you're recreating DataContext instances inside your ASP.Net page implementation, that, of course, does not lead to a DynamoDB request each time a page is reloaded. But if you're passing your own Table instance, please, cache it as well!