How to map User class to UserModel class using Emit Mapper?
public class User
{
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public IList<Role> Roles { get; set; }
public Company Company { get; set; }
}
public class UserModel
{
public Guid Id { get; set; }
public Guid CompanyId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public IList<RoleModel> Roles { get; set; }
}
There several problems:
- I need to flatten the object such that I will have CompanyId instead of the Company object.
- Company object has property Id, in the UserModel I have CompanyId which corresponds to the company id, but property names do not match.
- I need to map
List<Role>toList<RoleModel>
For flattering I was using configuration from the samples in Emit Mapper source files: http://emitmapper.codeplex.com/SourceControl/changeset/view/69894#1192663
To make the names to match in Company class should be the field with the name
IdFor mapping
List<Role>toList<RoleModel>I was using custom converter:So all together:
There is a problem, using Flatterning Configuration with Custom converters, check my question: Emit Mapper Flattering with Custom Converters