[英]Emit mapper domain model to view model
Can not seem to understand how to do the following mapping, there are two models of Domain EF: 似乎无法理解如何执行以下映射,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: 现在有一个ViewModel,我想在窗体上显示给用户:
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: 尝试使用Emit Mapper,但由于它实际上位于另一个表中,所以我无法理解如何实现映射字段NameA:
var mapper = ObjectMapperManager.DefaultInstance.GetMapper<B, B_ViewModel>();
I would be grateful for your help. 谢谢您的帮助。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.