views:

82

answers:

1

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)

    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)

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)
+1  A: 

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
Jay
yep, those are the backing fields. This is definitely what I'm looking for. So when I define a new StaffAndArticleViewModel it should look something like this ?Dim staffandarticle as new StaffAndArticleViewModel(a, b)
keynone
@keynone Yes, where `a` is an `Article` and `b` is a `Staff`. I made an assumption that you needed to expose one of each. You don't have to expose all the properties of both entities -- just what your view requires. You could also add properties that are "calculated" from values of the `Article` and `Staff` (these would probably be read-only).
Jay