Parent Child (Collection) mapping?

Nov 30, 2012 at 10:29 AM
Edited Nov 30, 2012 at 10:31 AM

I have two simple viewmodels which are related. I can query the data via an linq include statement (Parent an Children data is present), 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 child collection Object!

Injection:

viewModel.InjectFrom(dataObject)

Users are Nothing?

Coordinator
Nov 30, 2012 at 7:21 PM

maybe there's no Users property in the source object 

Dec 1, 2012 at 7:03 AM
Edited Dec 1, 2012 at 6:34 PM

If you mean by the source object the database there is a table for the user data (called USERTABLE) as you can see in the linq query and the data gets fetched but not mapped to the viewmodel via valueinjector.

Dec 4, 2012 at 7:13 AM

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