dimanche 10 mai 2015

Using AddRange with Distinct() is not working with Enum in MVC5 C#

I am trying to filter one of my enum fields from my model. Here's the definition of my enum:

public enum ProjectDifficulty
{
    Medium,
    High,
    [Display(Name = "Very High")]
    VeryHigh,
    Complex
}

But I cannot get the results; I see this error:

Cannot convert from 'System.Linq.IQueryable<Finder.Models.ProjectDifficulty>' to 'System.Collections.Generic.IEnumerable<string>'

My controller contains this code:

var ProjectDifficultyLst = new List<string>();

var ProjectDifficultyQry = from b in db.Projects
                           orderby b.ProjectDifficulty
                           select b.ProjectDifficulty;

ProjectDifficultyLst.AddRange(ProjectDifficultyQry.Distinct());

ViewBag.projectDifficulty = new SelectList(ProjectDifficultyLst);

if (!String.IsNullOrEmpty(projectDifficulty))
{
    SearchQry = SearchQry.Where(l => l.ProjectDifficulty == projectDifficulty);
}

Aucun commentaire:

Enregistrer un commentaire