Skip to content

IDynamoDBContext.ToDocument ignores read-only properties #1666

Open
@philBrown

Description

@philBrown

Description

Read-only POCO properties are ignored when creating a Document using IDynamoDBContext.ToDocument

These properties have values and should be included in the produced Document.

Reproduction Steps

Create a POCO with DynamoDB annotations and a read-only property (Greeting)

public class MyObject
{
    [DynamoDBHashKey("id")]
    public string Id { get; set; }

    [DynamoDBProperty("name")]
    public string Name { get; set; }

    [DynamoDBProperty("greeting")]
    public string Greeting => $"Hello, {Name}"
}

Create a Document and inspect the keys / values

var myobj = new MyObject
{
    Id = "my-id",
    Name = "Phil"
};
Console.WriteLine(myobj.Greeting); // "Hello, Phil"
var context = new DynamoDBContext(ddbclient);
var document = context.ToDocument(myobj);

Console.WriteLine(document.Count); // 2
Console.WriteLine(document.Keys.Contains("id")); // true
Console.WriteLine(document.Keys.Contains("name")); // true
Console.WriteLine(document.Keys.Contains("greeting")); // false

Environment

  • SDK Version: AWSSDK.DynamoDBv2 3.3.106.36
  • OS Info: Windows 10
  • Build Environment: Jetbrains Rider and dotnet CLI
  • Targeted .NET Platform: .Net Core 3.1

This is a 🐛 bug-report

Metadata

Metadata

Assignees

No one assigned

    Labels

    dynamodbfeature-requestA feature should be added or improved.p3This is a minor priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions