I'm playing around with DynamoDB for the first time ever, and it's my first time using an ORM. I'm trying to follow good practices around keeping Model seperate from controller. The project i'm using is a ASP.NET Web API for Lambda
I've written up my basic model and it looks like below
I have a User class
[DynamoDBTable("Users")]
public class User
{
[DynamoDBHashKey]
public string username { get; set; }
public string firstname { get; set; }
public string surname { get; set; }
and i have a Accounts class
[DynamoDBTable("Account")]
public class Account
{
[DynamoDBHashKey]
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
[DynamoDBLocalSecondaryIndexRangeKey]
public User User { get; set; }
My Account is associated with a user. Now i understand that as far as the database goes i want to store just the ID (username) of the user. But as far as in my Model. should i be storing the User object or just the Username? if i should store the User object, how do i save just the Key from the User object instead of the whole object.
On top of that if i am storing as a whole object. i wouldn't expect the client to post in the whole object, they would just post in the username. would the below code in the controller make sense? (note: DBContext is my database wrapper)
public void Post(Account NewAccount, String username)
{
User user = DBContext.GetItem<User>(username);
NewAccount.User = user
DBContext.StoreAsync(NewAccount);
}
Note: this code is not currently working due to the User object in Accounts.