Skip to content

Saving nested items with class hierarchies #2985

Closed
@atjohns

Description

@atjohns

Describe the bug

This is a similar issue to a very old discussion posted here on class hierarchies in Dynamo, but this one is explicitly about saving items. I am trying to use DynamoDB to save a model that mimics the following structure


    public class A
    {
        public string Name { get; set; }

        public int MyPropA { get; set; } = 1;
    }

    public class B : A
    {
        public int MyPropB { get; set; } = 2;
    }

    [DynamoDBTable("Test")]
    public class ModelA
    {
        [DynamoDBHashKey]
        public Guid id { get; set; }

        public List<A> MyClasses { get; set; }
    }

If we instantiate a new instance of this model like so...


            var a1 = new A { Name = "A1" };
            var b1 = new B { Name = "B1" };

            Guid id = Guid.NewGuid();

            var model = new ModelA
            {
                id = id,
                MyClasses = new List<A> { a1, b1 }
            };

We end up with a list that contains both Class B & Class A types that are being saved into Dynamo incorrectly.

Expected Behavior

Expectation would be for both Model A & Model B to save with the properties that are pushed by the code and be able to recognize the Model B inheritance

Current Behavior

When this model is saved to Dynamo it only saves the Class A properties. Here's a screenshot showing what the object looks like when the Save call is made vs what it looks like within Dynamo

image

Reproduction Steps

See above

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.DynamoDBv2 3.7.104

Targeted .NET Platform

.NET 7

Operating System and version

Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    dynamodbfeature-requestA feature should be added or improved.p2This is a standard priority issuequeued

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions