-
Notifications
You must be signed in to change notification settings - Fork 73
Closed
Description
If you use something like the following:
select * from People
left join PhoneNumbers on ...
If there are no phone numbers found you get back:
1, Joe, Bloggs, null, null
This causes a null ref when Slapper tries to map it as the Id on the phone number is null.
This should produce an empty list
See test below.
public class PersonWithProperties
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public List<PhoneNumber> Numbers { get; set; }
}
public class PhoneNumber
{
public int Id { get; set; }
public string Number { get; set; }
}
[Test]
public void Can_Map_Empty_Lists()
{
// Arrange
const int id = 1;
const string firstName = "Joe";
const string lastName = "Bloggs";
var dictionary = new Dictionary<string, object>
{
{ "Id", id },
{ "FirstName", firstName },
{ "LastName", lastName },
{ "Numbers_Id", null },
{ "Numbers_Number", null }
};
// Act
var customer = Slapper.AutoMapper.Map<PersonWithProperties>(dictionary);
// Assert
Assert.NotNull(customer);
Assert.That(customer.Id == id);
Assert.That(customer.FirstName == firstName);
Assert.That(customer.LastName == lastName);
Assert.NotNull(customer.Numbers);
Assert.That(customer.Numbers.Count() == 0);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels