I have a linq query that joins two tables (no relation in the actual db)
the relation is:
Companies 1 – n Phones
var miniCompanies =
(from companies in db.Companies
join phones in db.Phones on companies.Id equals phones.CompanyId
select new
{
companies.Name,
phones.Phone,
}).ToList().Distinct();
this returns something like:
----------------------------
company1 | 12345 |
----------------------------
company1 | 23456 |
----------------------------
company2 | 43242 |
----------------------------
company2 | 34234 |
----------------------------
company2 | 65442 |
----------------------------
i need to get only the fisrt in Phones table not everything
how to do that?
Edit:maybe i wasn’t clear about what want sorry for that.
i ment:
—————————-
company1 | 12345 |
—————————-
company2 | 43242 |
—————————-
i want the first phone for each company
You can use GroupBy: