我们需要存储从另一个表中提取的与我们的模型之一相关的数据列表。(我们构建得太深,无法将此关系添加到我们的数据库中应该在的位置。)当我们尝试将此列表加载到需要它的模型的属性中时。
我们将此列表加载到视图中的下拉列表中。尝试将此列表加载到控制器中的模型时发生错误。真正需要注意的是,我们在视图中的表中的每条记录都有一个唯一的下拉列表。
我们班:
Public class OurModel
public property ID As Integer
Public property First As Integer
Public property Last As Integer
Public property myList As List(Of SelectListItem)//This is our problem member
End class
控制器:
//This ViewModel is what we pass around from page to page to populate the various elements we need that is not tied to a specific model
Public Function LoadList(myViewModel As ViewModel) As Action Result
Using db //our database resource
For i As Integer = 0 to myViewModel.OurModel
//Assume table select statement previously declared and initialized into dbGet
**NOTE: dbGet is retieving data from a different table that is tied to this Model**
dbGet = dbGet.Where(Function(x) x.ID = myViewModel.OurModel.ID)
myViewModel.OurModel.myList = dbGet.ToList().[Select](Function(x) New SelectListItem() With {.Value = x.number, .Text = x.number})//ERROR IS HERE
Next
End Using
End Function
错误:
LINQ to Entities 无法识别方法“DB.ModelTable get_Item(Int32)”方法,并且该方法无法转换为存储表达式。
更新:问题似乎是 LINQ 正在尝试对我之前在此控制器中执行的查询的 DBContext 执行某些操作。错误引用DB.Employee
不是DB.Position
我要查询的内容。