none
Linq Distinct Select RRS feed

  • Question

  • Hi there

    i have got the following ling query

    List<SecurityAdministration.DataLayer.Patient> _patients;
     _patients = (from p in _dataContext.Patients
                 join ts in _dataContext.TrackedSamples
                 on p.PatientId equals ts.PatientId
                  where ts.SiteId == SiteID
                  select p).ToList<SecurityAdministration.DataLayer.Patient>();
        
    which returns

    PatientId   TestName   SiteID
     101           TEST1        2
     102           Test2         2
     101           Test1         2
     101           Test1         2
     
     How do i use Distinct on  where i got only
     PatientId  TestName  SiteID
      101          TEST1       2
      102          Test2        2
     
     
     thanks
     


    Friday, February 10, 2012 2:18 PM

Answers

  • Hi,

    try to use Disctinct operator. Something like that:

    List<SecurityAdministration.DataLayer.Patient> _patients;
      _patients = (from p in _dataContext.Patients
                  join ts in _dataContext.TrackedSamples
                  on p.PatientId equals ts.PatientId
                   where ts.SiteId == SiteID
                   select p).Distinct().ToList<SecurityAdministration.DataLayer.Patient>();
     

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.

    • Marked as answer by Rushdy Najath Friday, February 10, 2012 4:43 PM
    Friday, February 10, 2012 3:53 PM

All replies

  • Hi,

    try to use Disctinct operator. Something like that:

    List<SecurityAdministration.DataLayer.Patient> _patients;
      _patients = (from p in _dataContext.Patients
                  join ts in _dataContext.TrackedSamples
                  on p.PatientId equals ts.PatientId
                   where ts.SiteId == SiteID
                   select p).Distinct().ToList<SecurityAdministration.DataLayer.Patient>();
     

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.

    • Marked as answer by Rushdy Najath Friday, February 10, 2012 4:43 PM
    Friday, February 10, 2012 3:53 PM
  • ta thanks
    Friday, February 10, 2012 4:43 PM
  • See following

    http://stackoverflow.com/questions/543482/linq-select-distinct-with-anonymous-types

    Wednesday, February 15, 2012 8:35 AM