0
該聲明返回人員及其地址和電話號碼列表。如何在急速加載和集合中使用AutoMapper?
var listOfPeople = db.People.AsQueryable();
現在,我想使用AutoMapper將上述LINQ語句的結果映射到視圖模型。視圖模型主要是爲了防止某些屬性返回給客戶端/用戶而創建的。
如何獲得AutoMapper的結果,listOfPeople
映射,基礎對象,Person
組成的視圖模型,並Addresses
和PhoneNunmbers
ICollections
?我沒有將單個人映射到單個虛擬機的問題。我想我會掛上映射一個集合listOfPeople
,其中包含一些集合。
我使用ASP.NET Web API 4
,不MVC 4
這裏是視圖模型
public class BasicApiViewModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
public virtual ICollection<Phone> Phones { get; set; }
}
我還需要爲電話號碼和地址的集合映射類。然後,一切按預期工作。謝謝! – Scott