none
Find duplicate record and return the entire record not just the field containing the duplicate RRS feed

  • Question

  • Hi everyone,

    I'm new to LINQ and this is what I want to do.

    Access query:

    "SELECT Property.* From Property WHERE (((Property.[APPLICATIONSIDNUMBER]) In (SELECT [APPLICATIONSIDNUMBER] FROM [Property] As Tmp GROUP BY [APPLICATIONSIDNUMBER] HAVING Count(*)>1 ))) ORDER BY Property.[APPLICATIONSIDNUMBER], Property.[PremIDNumber] Desc;"

    How do I convert that query to LINQ.

    I'm using vb.net

    I have googled and have not been able to find an example.

    Thanks in advance.

    Ed

    Friday, December 15, 2017 12:41 PM

Answers

  • Hi egstatus,

    Please check the following code.

    var numbs = db.Properties.GroupBy(t => t.APPLICATIONSIDNUMBER).Where(t=> t.Count() >1).Select(t => t.Key);
    
    var query = db.Properties.Where(t => numbs.Contains(t.APPLICATIONSIDNUMBER)).OrderBy(t => t.APPLICATIONSIDNUMBER).ThenByDescending(t=>t.PremIDNumber).ToList();
            

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by egstatus Monday, December 18, 2017 1:07 PM
    Monday, December 18, 2017 6:20 AM
    Moderator

All replies

  • Hi egstatus,

    Please check the following code.

    var numbs = db.Properties.GroupBy(t => t.APPLICATIONSIDNUMBER).Where(t=> t.Count() >1).Select(t => t.Key);
    
    var query = db.Properties.Where(t => numbs.Contains(t.APPLICATIONSIDNUMBER)).OrderBy(t => t.APPLICATIONSIDNUMBER).ThenByDescending(t=>t.PremIDNumber).ToList();
            

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by egstatus Monday, December 18, 2017 1:07 PM
    Monday, December 18, 2017 6:20 AM
    Moderator
  • Thank you Zhanglong Wu,

    That is exactly what I was looking for.

    Best regards,

    EG.

    Monday, December 18, 2017 1:07 PM