我有一個真正的問題,我知道這是因爲我只是不夠了解。我搜查了大約50篇文章,找不到答案。MVC 3 ViewModel創建方法模型
這裏是我的域模型
Namespace Models
Public Class Article
Public Property ArticleId As Integer
Public Property Author As String
<DisplayFormat(DataFormatString:="{0:D}")>
Public Property CreatedOn As DateTime
<DisplayFormat(DataFormatString:="{0:D}")>
Public Property LastModified As DateTime
<AllowHtml()>
Public Property Content As String
Public Property Title As String
Public Property Excerpt As String
Public Property IsPublic As Boolean
Public Overridable Property Category As ICollection(Of Category)
Public Overridable Property Tags As ICollection(Of Tag)
Public Overridable Property Status As ICollection(Of Status)
Public Overridable Property Comments As ICollection(Of Comment)
End Class
End Namespace
Namespace Models
Public Class Status
Public Property StatusId As Integer
Public Property Name As String
Public Overridable Property Articles As ICollection(Of Article)
End Class
End Namespace
Namespace Models
Public Class Category
Public Property CategoryId As Integer
Public Property Name As String
Public Overridable Property Articles As ICollection(Of Article)
End Class
End Namespace
Namespace Models
Public Class Tag
Public Property TagId As Integer
Public Property Name As String
Public Overridable Property Articles As ICollection(Of Article)
End Class
End Namespace
這裏是我的視圖模型(基於我的域模型)
Namespace ViewModels.Admin
Public Class ArticleViewModel
Public Property Article As Article
Public Property CategoryId As Integer
Public Property StatusId As Integer
Public Property Tags As ICollection(Of Tag)
End Class
End Namespace
我不知道如何使用這些數據交叉圖案的節省。我現在嘗試了很多方法,我不知道在哪裏看。我已經嘗試了幾本書,但沒有人真正深入這一點。我也看看Contoso大學的項目,但它看起來不像我的項目。誰能幫忙?
要保存他們做些什麼呢至? – smartcaveman
如果有幫助,請參閱下面的評論。我通過EF代碼第一個模型將它們保存到數據庫中。 – Chuck