What is a type of correspondingDropDownValue
? Suppose it's IQueryable<T>
, right? At first, you need to get all required fields from the database, then cast result to IEnumerable<T>
and only then - create SelectListItems
list. Something like this:
correspondingDropDownValue
.Select(j => new {Value = j.UserID, Text = j.SomeTextField}) // SELECT UserID, SomeTextField FROM SomeTable
.AsEnumerable() // Evaluate the query
.Select(j => new SelectListItem // Work with in-memory objects using LINQ to Objects instead of LINQ to Entities
{
Value = j.Value.ToString(),
Text = j.Text,
Selected = j.Value == x.DefaultValue
})
.ToList()