We need to store a list of data we pull from another table that relates to one of our models. (We are too deep into build to add this relationship to our DB where it should be.) When we attempt to load this list in a property of the model that needs it.
We load this list into a dropdown in a view. The error occurs trying to load this list into the model in the controller. The true caveat is that we have a unique dropdown list for each record in our table in the view.
Our Class:
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
Controller:
//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
Error:
LINQ to Entities does not recognize the method ‘DB.ModelTable get_Item(Int32)’ method, and this method cannot be translated into a store expression.
UPDATE: The issue appears to be that LINQ is trying to do something with a the DBContext of a query I do previously in this controller. The error is referencing DB.Employee not DB.Position which is what I am querying.
I ended up having to write new classes that connected to the database outside of Entity Framework. If you want to use Entity Framework, make sure you database design is PERFECT before you begin building your application and good luck.