Skip to content

Slapper behavior for dynamic object's child objects #32

@digaomatias

Description

@digaomatias

In my application we have a scenario where the dynamic objects returned from the query can have a null child.

Consider the user object being like this:

public class User 
{
    public int Id { get; set; }
    public string Name { get; set; }
    public Address Address { get; set; }
}

For example, if I do a query to retrieve one user and it doesn't have an address yet:

SELECT 
    U.Id, 
    U.Name, 
    U.Address_Id 
FROM Users U

This is the dynamic object returned:

{{ DapperRow, Id = '1', Name = 'Dummy User', Address_Id = NULL }}

What happens here when I use AutoMapper.MapDynamic(result) is that the User object created contains an empty instance of Address. Slapper maps the null Address_Id into an empty instance of Address with Id=0.
This could cause errors if after retrieving the object from the database, we try to save it back. It would have a reference to an object with id=0, the update on the database would break with foreign key constraint.

Is there a way to tell Slapper to not map null values to empty child objects? I would prefer to map null instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions