【发布时间】:2015-03-18 02:50:29
【问题描述】:
我做了很多搜索,但不确定如何使用 Automapper 收集地图。
给定:
Public Class PostSummaryDTO
Public Property PostId As Integer
Public Property PostGuid As Guid
Public Property PostTitle As String
Public Property PostSummary As String
Public Property PostDateCreated As DateTime
Public Property PostIsPublished As Boolean
Public Property PostText As String
Public Property PostCategory As ICollection(Of be_Categories)
Public Property PostTag As ICollection(Of be_PostTag)
Public Author As String
End Class
和
Public Class be_PostsViewModel
Public Property Id As Integer
Property Author As String
<DisplayName("Title")> <Required(ErrorMessage:="Your post must have a title")>
Public Property PostTitle As String
<DisplayName("My Snarky Text")> Public Property PostSummary As String
<DisplayName("Post")> Public Property PostText As String
<UIHint("DateCreated")> <DisplayName("Date Created")> Property PostDateCreated
As DateTime?
<DisplayName("Publish")> Public Property PostIsPublished As Boolean
Public Property PostGuid As Guid
Public Property BlogId As Guid
<DataType(DataType.MultilineText)> <UIHint("Tags")> <DisplayName("Tags")>
Public Property PostTags As ICollection(Of be_PostTag)
<DisplayName("Category")> <UIHint("Categories")> Public Property
PostCategory As ICollection(Of CategoriesViewModel)
End Class
如何将Public Property PostCategory As ICollection(Of be_Categories) 映射到Public Property PostCategory As ICollection(Of CategoriesViewModel)
【问题讨论】:
-
检查这个问题stackoverflow.com/questions/13687240/…,它应该很简单,只需 Map
,当你有一个集合或列表时这就足够了。
标签: vb.net collections asp.net-mvc-5 automapper entity-framework-6.1