我有這樣的實體:複製實體內部視圖模型
public class MyEntity : IMergeable<Entities.EntityExample>
{
[Required]
public string Code { get; set; }
[Required]
public string Label{ get; set; }
public System.DateTime DateStart { get; set; }
}
我想複製它在視圖模型,將有一個名爲DateEnd第4財產。我在想這樣做:
namespace MyNamespace.ViewModels
{
public class ExampleViewModel
{
public ExampleViewModel(MyEntity myEntity)
{
myentity = myEntity;
}
public myEntity myentity { get; set; }
[Required]
public string DateEnd { get; set; }
}
}
這工作,但我的問題是,我的視圖模型將被安排在下列方式:
myViewModel.myentity.Code
myViewModel.myentity.Label
myViewModel.myentity.DateStart
myViewModel.DateEnd
當我真正想要的是:
或者至少(不太好):
myViewModel.myentity.Code
myViewModel.myentity.Label
myViewModel.myentity.DateStart
myViewModel.myentity.DateEnd
請考慮https://github.com/AutoMapper/AutoMapper – tschmit007
我會的,謝謝你 –