c# - Load distinct values from database into List<> -


i made record poco class foreign key event (=sport discipline). record can linked 1 event event can have multiple records (world record, olympic record, etc..). want print each event(+attached records) in database for-each loop index view.

but because table record hasn't got list property, have create local (distinct)list of events record table , there's problem.

for additional info, here record model

    public class record {     [key]     public int recordid { get; set; }     public string resultname { get; set; }     public int resultage { get; set; }     public double resultprestation { get; set; }     public system.datetime resultdate { get; set; }     public string resultplace { get; set; }     public int countryid { get; set; }       [foreignkey("countryid")]     public virtual country country {get; set;}     public int eventid { get; set; }     [foreignkey("eventid")]     public virtual event event { get; set; } } 

and event model

    public class event {     [key]     public int eventid { get; set; }     public string sport { get; set; }     public string discipline { get; set; }     public boolean schoolcupevent { get; set; }     public list<record> records { get; set; } } 

i wrote little piece end list of events witch record exists, but not distinct list , that's need.

        list<event> events = new list<event>();         foreach(var item in db.records)         {                            event e = db.events.find(item.eventid);             events.add(e);         } 

i hope can me.

regards

var events = db.records.distinct().tolist(); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -