开发者

MVC2 Multiple Model definition from linq to sql class VB.net

I call upon the VB ninjas out there. Here's my situation. I need to eventually be able to pass multiple models to a view. Currently I have a linq to sql class that, of course, has a bunch of generated model definitions. I need to make a model that implements multiple models. I somewhat understand how to do this in C#, but this project is testing my VB skillz.

Here's some snippets from my linq to sql models. I need to combine these two into one model to pass to the view.

Article model:

<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)

    Pri开发者_C百科vate _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)

Staff model:

<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)


I might be missing the point of the question, but the first issue is that everything in these classes is Private. Maybe you're just showing the backing fields?

Assuming so, it seems like you just want to compose and expose some data from these objects through a presentation model:

Public Class StaffAndArticleViewModel
    Private _Article As Article
    Private _Staff As Staff

    Public Sub New(ByVal a As Article, ByVal s As Staff)
        _Article = a
        _Staff = s
    End Sub

    ' now you just expose everything that the view requires
    ' for example:

    Public Property StaffName As String
        Get
            Return _Staff.Staff
        End Get
        Set(ByVal Value As String)
            _Staff.Staff = Value
        End Set
    End Property
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜