You must Sign In to post a response.
  • Category: LINQ

    How to filter the duplicate records from datatable using linq?


    Are you looking for a way to filter the duplicate records from datatable using linq? then read this thread to know how to do it in linq



    Hi
    I need linq query to delete the duplicate records from the datatable that contains specific words in that datacolumn. Kindly give me the solution for this problem.


    In Datatable, i have the following rows

    studentid studentname coursename
    1 Abhi Course - I
    1 Abhi Course - II



    [Hint : I need to filter the duplicate records based on Coursename contains the word Course]


    Expected Output:

    studentid studentname coursename
    1 Abhi Course - I
  • #750181
    try the below query which uses the keywords:

    var res =( (from d in details where d.CourseName.Contains("Course") select d).Take(1)
    .Union((from a in details where !a.CourseName.Contains("Course") select a)));

    In the above query first we are taking only one record which contains the Course keyword. Take keyword is used to limit the number of records selected. Then we are using the Union keyword to join the previous result with the result of the query which returns the records whose course name does not contain the keyword Course.

    We are joining both the queries using the Union keyword on linq.

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net


  • Sign In to post your comments