Question

Can not seem to understand how to do the following mapping, there are two models of Domain EF:

public class A
{
     public int Id {get; set;}
     public string Name {get; set;}
}

public class B
{
     public int Id {get; set;}
     public string EmplName
     public int AId {get; set;}
     public virtual A A { get; set; }
}

Now there is one ViewModel, which I want to display on the form to the user:

public class B_ViewModel
{
     public int Id {get; set;}
     public string EmplName {get; set;}
     public string NameA {get; set;}
}

Trying to use Emit Mapper, but I can not understand how to implement the mapping field NameA, since it is actually located in another table:

var mapper = ObjectMapperManager.DefaultInstance.GetMapper<B, B_ViewModel>();

I would be grateful for your help.

Was it helpful?

Solution

You just need two mappers:

var mapper1 = ObjectMapperManager.DefaultInstance.GetMapper<A, B_ViewModel>();
var mapper2 = ObjectMapperManager.DefaultInstance.GetMapper<B, B_ViewModel>();

var result = new B_ViewModel();
mapper1.Map(a, result); 
mapper2.Map(b, result); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top