I am sure this is simple and I am just missing something...
I have a view component:
public IViewComponentResult Invoke(int id) { var supplierContacts = _context.SupplierContact .Where(s => s.SupplierID== id ) .Distinct(); return View(supplierContacts); }
The invoke statement is returning correctly the records for the supplier contacts. For example Peter and Raj work for Techsource returns fine.
Where I am having issues is where the supplier contact has two forms of contact, say mobile phone and email, this is returning the contact persons name twice.
So instead of:
Peter
Phone
Raj
The result is
Peter
Phone
Peter
Phone
Raj
I can kind of see why this is. After all the only restriction I am passing to the expression is the SupplierID and I can also see that the records are not distinct in SupplierContact as there is a listing with an email and then separately a listing with the phone etc.
I just cant see how to write something like:
var supplierContacts = _context.SupplierContact .Where(s => s.SupplierID== id ) .Distinct(SupplierConact.Name);
How do I force the statement to return just the distinct names in supplierContact without breaking the IEnumerable in the view?