I'm using VB.Net, MVC 5, EF 6, and Linq. I have a list of Integers
(category attribute IDs). I need to create a second list of String
(values). There will be one string
for each integer
.
I am currently accomplishing my task like this:
Function getValues(catAttIDs As List(Of Integer), itemID As Integer) As List(Of String)
Dim db As New Model1
Dim values = New List(Of String)
For i As Integer = 0 To catAttIDs.Count - 1
Dim catAttID = catAttIDs(i)
Dim currentValue = (From row In db.tblEquipment_Attributes
Where row.Category_Attribute_Identifier = catAttID _
And row.Unique_Item_ID = itemID
Select row.Value).SingleOrDefault()
values.Add(currentValue)
Next
Return values
End Function
I have a strong feeling that there is a better way to do this, but I have not been able to find the information I'm looking for.
I'm particularly interested in changing this code so that the database is called once for the list, instead of calling the database 5 or 6 times as I work my way through the list.