I've got a situation where I have a list of Organization
s (code to follow), and a user has a list of OrganizationIds (int
s). I want to filter down the full list of Organizations using the User's OrganizationId list for a dropdown list. The query works, but it feels like there may be a more optimal way to write it. Is there, or am I already pretty much optimized?
public class Organization
{
public int Id { get; set; }
public string Division { get; set; }
public bool IsActive { get; set; }
public bool IsDefault { get; set; }
public string Name { get; set; }
}
Query
vm.locations = _organizations.GetOrganizations().Where(o => ((ApplicationUser)User).OrganizationIdList.Any(u => u == o.Id)).Select(org =>
new SelectListItem
{
Text = org.Division + " - " + org.Name,
Value = org.Id.ToString()
}).OrderBy(item => item.Text);