开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜