asp.net mvc - Trouble when using C# .Distinct() -


i trying fill dropdown list of regions come database. regions coming table there can many rows same region, using .distinct() display 1 of each in dropdown. lets there 100 northwest's in database. using .distinct() group them 1 northwest displayed in dropdown.

i added ability disable , enable regions, don't want affect how viewed in dropdown, used other functionality. user has ability disable or enable of 100 in model (may not make sense, has purpose). enabled , disabled bit value in database. issue comes if there @ least 1 northwest enabled , 1 disabled. calling regionstate has true value , false value meaning displays twice in dropdown because distinct eachother.

var context = new testcontext(); var viewmodel = new testviewmodel();  viewmodel.regions = context.select(r => new region     { name = r.region,       regionstate = r.regionstate     }).distinct().orderby(r => r.name); 

viewmodel:

    public class testviewmodel     {     public ienumerable<region> regions;     } 

model:

    public class region     {     public string name;     public bool regionstate { get; set; }     } 

how use .distinct() filter based on name, while allowing regions both true , false regionstate appear 1 in dropdown. need keep regionstate in viewmodel.

let me know if have questions. may bit confusing.thanks!

filter before applying distinct using where

viewmodel.regions = context.where(r => r.propertythatindicatesitisenabled)                            .select(r => new region { name = r.region, regionstate = r.regionstate })                            .distinct()                            .orderby(r => r.name) 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -