AutoMapper - Mapping View Model Collections?
So I have a View Model like this:
Public Class CategoryViewModel
Public Property ID As Integer
Public Property Name As String
Public Property Display As Boolean
Public Property DisplayIndex As Integer
End Class
And then this:
Public Class CategoriesViewModel
Public Property Categories As IEnumerable(Of CategoryViewModel)
End Class
How do I map a collection of categories (Domain.Category) to the Categories (CategoryViewModel) property in the CategoriesViewModel?
Also, how would you handle a collection of Sub Categories? Would you make another View Model for that and have a collection 开发者_开发技巧of those on the CategoryViewModel?
Just tell automapper how the types should map, so tell AM how Category maps to CategoryViewModel. AM doesn't care if you map an array of categories to a list of categoriesviewmodel as long as you tell it how to map the types.
For the second part are sub categories self referencing?
精彩评论