物件永續性模型示例
這個例子由兩部分組成:首先,我們必須定義我們的 Book
型別; 第二,我們將它與 DynamoDBContext
一起使用。
[DynamoDBTable("Books")]
class Book
{
[DynamoDBHashKey]
public int Id { get; set; }
public string Title { get; set; }
public List<string> Authors { get; set; }
public double Price { get; set; }
}
現在,將它與 DynamoDBContext
一起使用。
var client = new AmazonDynamoDBClient();
DynamoDBContext context = new DynamoDBContext(client);
// Store item
Book book = new Book
{
Title = "Cryptonomicon",
Id = 42,
Authors = new List<string> { "Neal Stephenson" },
Price = 12.95
};
context.Save(book);
// Get item
book = context.Load<Book>(42);
Console.WriteLine("Id = {0}", book.Id);
Console.WriteLine("Title = {0}", book.Title);
Console.WriteLine("Authors = {0}", string.Join(", ", book.Authors));