0

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

视图模型:

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)

用户什么都不是?

4

1 回答 1

0

好的,在这个问题的帮助下弄清楚了:如何使用 ValueInjector 映射列表

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

询问:

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

注射:

Dim viewModel = New EventViewModel
viewModel.USERS= dataSubObject.Select(Function(x) New ImageViewModel().InjectFrom(x)).Cast(Of ImageViewModel)().ToList()
于 2012-12-04T07:12:35.363 回答