我有以下doimain对象:ASP.NET MVC与AutoMapper(填充视图模型从父和子域对象)
public class ComponentType
{
public int ComponentTypeID { get; set; }
public string Component_Type { get; set; }
public string ComponentDesc { get; set; }
}
public class AffiliateComponentType
{
public int AffiliateComponentID { get; set; }
public int AffiliateID { get; set; }
public ComponentType ComponentType { get; set; }
public bool MandatoryComponent { get; set; }
public bool CanBeBookedStandalone { get; set; }
public int PreferenceOrder { get; set; }
}
我会使用NHibernate从数据库得到AffiliateComponentType的列表。现在,我必须从AffiliateComponentType域对象的LIST填充AffiliateComponentTypeView(View Model)列表。我如何使用AutoMapper实现这一目标?
[Serializable]
public class AffiliateComponentTypeView
{
public int ComponentTypeID { get; set; }
public string Component_Type { get; set; }
public string ComponentDesc { get; set; }
public bool MandatoryComponent { get; set; }
public bool CanBeBookedStandalone { get; set; }
public int PreferenceOrder { get; set; }
}
感谢达林。我使用了你建议的第一种方法。非常感谢... – Alex 2011-02-07 18:30:50