Question: I made a Record POCO class with a foreign key to an Event (=sport discipline).
A record can be linked to 1 event but an event can have multiple records (world record, olympic record, etc..).
Now I want to print each event(+attached records) in the database with a for-each loop to the Index view.

But because table Record hasn't got a List property, I have to create a local (Distinct)List of events from my Record table and there's my problem.

For additional info, here is my 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 the 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 a little piece where I end up with a List of Events for witch a Record exists, **but this is not a Distinct list** and that's what i 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 someone can help me.

Regards

Answer: 
```
var events = db.Records.Distinct().ToList();

```
How about putting events in Set which will remove duplicates if any and then convert set back to the list.

```
Set<Event> eventSet = new TreeSet<Event>();
foreach(var item in db.Records)
{               
        Event e = db.Events.Find(item.EventId);
        eventSet.Add(e);
}
List<Event> eventList = new ArrayList<Event>();
if(eventSet != null && eventSet.size() > 0)
{
        eventList.add(eventSet);
}

```