1
比方說,我有一個域對象是這樣的:什麼是不忽略Automapper中未使用的屬性的後果?
public class Product
{
public int Id {get;set;}
public string Name {get;set;}
public string Description {get;set;}
public int DisplayOrder {get;set;}
//Lots of other properties
}
對於我的觀點不過,我想用使用該產品類別的不同屬性2個不同的視圖模型。
public class ProductViewModel1
{
public int Id {get;set;}
public string Name {get;set;}
//A mix of some of the other properties
}
public class ProductViewModel2
{
public int Id {get;set;}
public string Description {get;set;}
//A different mix of the other properties
}
對於Automapper:
Mapper.CreateMap<Product, ProductViewModel1>();
Mapper.CreateMap<Product, ProductViewModel2>();
問題(S): 是否有必要添加所有的忽略屬性CreateMap?如果不在較大的對象上完成這項工作,是否會有大量開銷?謝謝。
感謝保羅。該鏈接很有用,因爲它引用了一個擴展方法,用於忽略單元測試中的所有未映射屬性。 – trevorc