LINQ - how to remove duplicate rows in table

Wexoni

After certain proccess, I wan to remove duplicates from the table and commit the changes, so only single values remain.

I have three criteria for removal:

  • Name
  • date
  • status (is always 1)

So if there are records with same Name, and same date and same status... remove one. Does not matter which one.

I have: dbContext.tbl_mytable

sgmoore

Since you are talking about deleting records, you need to test this first.

So if there are records with same Name, and same date and same status... remove one. Does not matter which one.

I'm assuming you want to remove all but one, ie, if you have three records with the same details, you remove two and leave one.

If so, you should be able to identify the duplicates by grouping by { Name, date, status} and then selecting all except the first record in each group.

ie something like

var duplicates = (from r in dbContext.tbl_mytable 
                  group r by new { r.Name, r.date, r.status} into results
                  select results.Skip(1)
                 ).SelectMany(a=>a);

 dbContext.tbl_mytable.DeleteAllOnSubmit(duplicates);
 dbContext.SubmitChanges();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to remove duplicate rows

From Dev

Jquery: How to remove duplicate HTML TABLE rows based on columns values

From Dev

SQL - Remove Duplicate Rows From Table

From Dev

Remove duplicate rows on many to many table (Mysql)

From Dev

Duplicate and Remove Table Rows through Jquery

From Dev

Remove duplicate rows on many to many table (Mysql)

From Dev

LINQ to remove duplicate rows from a datatable based on the value of a specific row

From Dev

LINQ to remove duplicate rows from a datatable based on the value of a specific row

From Dev

How to remove duplicate record using linq?

From Dev

How to remove duplicate records from LINQ query

From Dev

How to remove duplicate nodes in linq to xml document

From Dev

How to remove duplicate record using linq?

From Dev

How to remove duplicate records from LINQ query

From Dev

How to remove duplicate rows with CTE when partitioning by another table's column?

From Dev

How to retain a row which is foreign key in another table and remove other duplicate rows?

From Dev

how to remove duplicate records but need to keep their child table rows and tag them to survived row

From Dev

How to remove duplicate rows with CTE when partitioning by another table's column?

From Dev

How can I remove subsequent duplicate rows from a table in a sorted order?

From Dev

How can I remove duplicate rows from a table but keeping the summation of values of a column

From Dev

How to remove duplicate rows from a join (SQL)

From Dev

How to remove duplicate rows with foreign keys dependencies?

From Java

How can I remove duplicate rows?

From Dev

How to remove consecutive duplicate rows in KDB?

From Dev

How to remove duplicate rows based on some columns

From Dev

How to write a query to remove duplicate rows?

From Dev

How to efficiently remove duplicate rows from a DataFrame

From Dev

How to remove duplicate rows in SQL Server

From Dev

How to remove duplicate rows from nested list?

From Dev

How remove rows of html table?

Related Related

  1. 1

    how to remove duplicate rows

  2. 2

    Jquery: How to remove duplicate HTML TABLE rows based on columns values

  3. 3

    SQL - Remove Duplicate Rows From Table

  4. 4

    Remove duplicate rows on many to many table (Mysql)

  5. 5

    Duplicate and Remove Table Rows through Jquery

  6. 6

    Remove duplicate rows on many to many table (Mysql)

  7. 7

    LINQ to remove duplicate rows from a datatable based on the value of a specific row

  8. 8

    LINQ to remove duplicate rows from a datatable based on the value of a specific row

  9. 9

    How to remove duplicate record using linq?

  10. 10

    How to remove duplicate records from LINQ query

  11. 11

    How to remove duplicate nodes in linq to xml document

  12. 12

    How to remove duplicate record using linq?

  13. 13

    How to remove duplicate records from LINQ query

  14. 14

    How to remove duplicate rows with CTE when partitioning by another table's column?

  15. 15

    How to retain a row which is foreign key in another table and remove other duplicate rows?

  16. 16

    how to remove duplicate records but need to keep their child table rows and tag them to survived row

  17. 17

    How to remove duplicate rows with CTE when partitioning by another table's column?

  18. 18

    How can I remove subsequent duplicate rows from a table in a sorted order?

  19. 19

    How can I remove duplicate rows from a table but keeping the summation of values of a column

  20. 20

    How to remove duplicate rows from a join (SQL)

  21. 21

    How to remove duplicate rows with foreign keys dependencies?

  22. 22

    How can I remove duplicate rows?

  23. 23

    How to remove consecutive duplicate rows in KDB?

  24. 24

    How to remove duplicate rows based on some columns

  25. 25

    How to write a query to remove duplicate rows?

  26. 26

    How to efficiently remove duplicate rows from a DataFrame

  27. 27

    How to remove duplicate rows in SQL Server

  28. 28

    How to remove duplicate rows from nested list?

  29. 29

    How remove rows of html table?

HotTag

Archive