-
Notifications
You must be signed in to change notification settings - Fork 73
Description
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 UThis 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.