Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Going in Cricles on Distinct Record Returns

$
0
0

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

Email

Phone

Raj

Email

The result is

Peter

Email

Phone

Peter

Email

Phone

Raj

Email

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?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>