0
我呼籲VB忍者在那裏。這是我的情況。我需要最終能夠將多個模型傳遞給視圖。目前我有一個LINQ到SQL類,當然,它有一堆生成的模型定義。我需要製作一個模型來實現多個模型。我有點理解如何在C#中做到這一點,但這個項目正在測試我的VB技能。MVC2多模型定義從LINQ到SQL類VB.net
這是從我的linq到sql模型的一些片段。我需要將這兩個結合到一個模型中傳遞給視圖。
文章型號:
<Global.System.Data.Linq.Mapping.TableAttribute(Name:="dbo.Articles")> _
Partial Public Class Article
Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty)
Private _ArticleID As Integer
Private _ClassID As System.Nullable(Of Integer)
Private _Title As String
Private _ShortDescription As String
Private _LongDescription As String
Private _ByLine As String
Private _ArticleDate As System.Nullable(Of Date)
Private _SchoolClass As EntityRef(Of SchoolClass)
員工型號:
<Global.System.Data.Linq.Mapping.TableAttribute(Name:="dbo.Staff")> _
Partial Public Class Staff
Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty)
Private _StaffID As Integer
Private _ClassID As Integer
Private _PositionID As System.Nullable(Of Integer)
Private _StaffName As String
Private _Position As EntityRef(Of Position)
Private _SchoolClass As EntityRef(Of SchoolClass)
是的,這些都是支持字段。這絕對是我正在尋找的。所以當我定義一個新的StaffAndArticleViewModel時,它應該看起來像這樣? Dim staffandarticle as new StaffAndArticleViewModel(a,b) – keynone 2010-08-08 01:45:05
@keynone是的,其中'a'是'Article'和'b'是'Staff'。我做了一個假設,你需要公開其中的一個。您不必公開兩個實體的所有屬性 - 正是您的觀點所需要的。您還可以添加「Article」和「Staff」值的「計算」屬性(這些屬性可能是隻讀的)。 – Jay 2010-08-08 01:49:25