我試圖讓AutoMapper工作,並且真的陷入了一個簡單的任務。我在用戶實體定義的複雜類型:Automapper,複雜的屬性和繼承
[ComplexType]
public class CustomerProfile
{
public string FirstName { get; set; }
public string LastName { get; set; }
// ...
}
public class User
{
public long Id {get; set;}
public string Email { get; get; }
public CustomerProfile CustomerProfile { get; set; }
}
我有這樣的視圖模型:
public class CustomerViewModel : CustomerProfile
{
public string Email { get; set; }
}
所以我只是有所有的CustomerProfile性質的視圖模型以及電子郵件。
我想將用戶映射到CustomerViewModel。我嘗試了一切,但實際上並沒有成功。即使此代碼不起作用:
Mapper.CreateMap<CustomerProfile, CustomerViewModel>();
Automapper只是拒絕映射任何東西。
它如何映射?謝謝。
是什麼那「不起作用」,它不起作用? – Default 2014-10-30 12:27:26