Search code examples
vb.netlinqviewmodelvalueinjecter

ValueInjecter and ICollection(Of ViewModel)


I have two simple viewmodels which are related. I can query the data via an linq include statement, but when i inject it into the viewmodel the icollection is nothing?

Viewmodels:

Public Class EventViewModel
  Public Property EVENTID As Integer
  Public Property TITLE As String

  Public Overridable Property USERS() As ICollection(Of UserViewmodel)
End Class

Public Class UserViewModel
  Public Property USERID As Integer
  Public Property EVENTID As Integer
  Public Property NAME As String
End Class

Query:

Dim dataObject As EVENTTABLE = db.EVENTTABLE.Include("USERTABLE").Single(Function(c) c.EVENTID= "1")

Users are in the Object!

Injection:

viewModel.InjectFrom(dataObject)

Users are Nothing?


Solution

  • Ok figured it out with help from this question: How to map lists with ValueInjector

    I needed to query the USERTABLE into a list and inject it like stated below:

    Query:

    Dim dataSubObject = (From ....).toList()
    

    Injection:

    Dim viewModel = New EventViewModel
    viewModel.USERS= dataSubObject.Select(Function(x) New ImageViewModel().InjectFrom(x)).Cast(Of ImageViewModel)().ToList()