petrov.alex
petrov.alex

Reputation: 1089

EmitMapper Flattering Config NullReferenceException

I am using EmitMapper with Flattering Configuration form EmitMapper samples to map my Entities to DTOs.

The problem is the I am getting NullReferenceException in the case if the source value is the property of the object, which is null, for example:

public class User
{
  public Guid Id { get; set; }
  public Company Company { get; set; }
}    

public class Company
{
  public Guid Id { get; set; }
}

public class UserDTO
{
  public Guid Id { get; set; }
  public Guid CompanyId{ get; set; }
}

I am mapping User to UserDTO: var mapper = ObjectMapperManager.DefaultInstance.GetMapper<User, UserDTO>( new FlatteringConfig() );

var dto = mapper.Map(new User());

When EmitMapper will try to get CompanyId, it will call the getter of Company object Id property, but it is null.

Any help will be much appriciated.

Upvotes: 1

Views: 320

Answers (0)

Related Questions