ValueInjecter和ICollection(Of ViewModel)

时间:2012-11-30 08:22:23

标签: vb.net linq viewmodel valueinjecter

我有两个相关的简单视图模型。我可以通过linq include语句查询数据,但是当我将它注入viewmodel时,icollection什么都没有?

的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

查询:

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

用户在对象中!

注射:

viewModel.InjectFrom(dataObject)

用户什么都没有?

1 个答案:

答案 0 :(得分:0)

好的,在这个问题的帮助下找到了它:How to map lists with ValueInjector

我需要将USERTABLE查询到一个列表中并像下面所述注入它:

查询:

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

注射:

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