Update Multiple columns of multiple rows using LINQ

ankur

I am using Entity framework for building an app.

Table to be updated.

[Id] [CheckItemId]  [Checked]  [Comment]
1      100             1          abc
2      150             0          xyz

Class:

public class CheckListRequest
{
    public int ID { get; set; }
    public bool IsChecked { get; set; }
    public string Comment { get; set; }
}

public static void UpdateCheckList(List<CheckListRequest> checkList){

}

How do I update the table multiple column like (Checked,comment) with the values coming in list from frontend using LINQ?

ekad

Assuming dbContext is your DataContext and Id is the primary key of the table, try this:

public static void UpdateCheckList(List<CheckListRequest> checkList)
{
    foreach (CheckListRequest clr in checkList)
    {
        CheckListRequest clrInDB = dbContext.CheckListRequests.SingleOrDefault(o.Id == clr.Id);
        clrInDB.IsChecked = clr.IsChecked;
        clrInDB.Comment = clr.Comment;
    }

    dbContext.SaveChanges();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update Multiple columns of multiple rows using LINQ

From Dev

Update multiple columns in linq using lambda expressions

From Dev

linq query to update multiple rows

From Dev

Changes(update) not commited to multiple columns using LINQ to SQL

From Dev

Update multiple rows/columns in php/mysql

From Dev

Update multiple columns for multiple rows in one query of SQL

From Dev

Update multiple columns with data retrieved from multiple rows of same table

From Dev

Selecting Multiple Rows from DataGridView using Linq

From Dev

Selecting Multiple Rows from DataTable using Linq

From Dev

how to group by multiple columns using linq

From Dev

Group & Aggregate multiple columns using LINQ

From Dev

how to group by multiple columns using linq

From Dev

Updating multiple columns and rows using PDO

From Dev

Inserting rows with multiple columns into BigQuery using Avro

From Dev

how to concatenate columns with multiple rows using awk

From Dev

Pandas: Update Multiple Dataframe Columns Using Duplicate Rows From Another Dataframe

From Java

Update multiple rows in same query using PostgreSQL

From Dev

Update multiple rows using hibernate Criteria

From Dev

Update multiple rows using CASE WHEN - ORACLE

From Dev

Update multiple rows using single value

From Dev

how to update multiple rows using php script

From Dev

Update multiple rows using select statements

From Dev

How to update multiple columns in mysql using php

From Dev

Oracle update statement using multiple columns

From Dev

An efficient way to update multiple columns using join

From Dev

update multiple columns using case statement in sql

From Dev

Convert Multiple Rows into Multiple Columns

From Dev

From Multiple rows into multiple columns

From Dev

Linq Group By Multiple Columns

Related Related

  1. 1

    Update Multiple columns of multiple rows using LINQ

  2. 2

    Update multiple columns in linq using lambda expressions

  3. 3

    linq query to update multiple rows

  4. 4

    Changes(update) not commited to multiple columns using LINQ to SQL

  5. 5

    Update multiple rows/columns in php/mysql

  6. 6

    Update multiple columns for multiple rows in one query of SQL

  7. 7

    Update multiple columns with data retrieved from multiple rows of same table

  8. 8

    Selecting Multiple Rows from DataGridView using Linq

  9. 9

    Selecting Multiple Rows from DataTable using Linq

  10. 10

    how to group by multiple columns using linq

  11. 11

    Group & Aggregate multiple columns using LINQ

  12. 12

    how to group by multiple columns using linq

  13. 13

    Updating multiple columns and rows using PDO

  14. 14

    Inserting rows with multiple columns into BigQuery using Avro

  15. 15

    how to concatenate columns with multiple rows using awk

  16. 16

    Pandas: Update Multiple Dataframe Columns Using Duplicate Rows From Another Dataframe

  17. 17

    Update multiple rows in same query using PostgreSQL

  18. 18

    Update multiple rows using hibernate Criteria

  19. 19

    Update multiple rows using CASE WHEN - ORACLE

  20. 20

    Update multiple rows using single value

  21. 21

    how to update multiple rows using php script

  22. 22

    Update multiple rows using select statements

  23. 23

    How to update multiple columns in mysql using php

  24. 24

    Oracle update statement using multiple columns

  25. 25

    An efficient way to update multiple columns using join

  26. 26

    update multiple columns using case statement in sql

  27. 27

    Convert Multiple Rows into Multiple Columns

  28. 28

    From Multiple rows into multiple columns

  29. 29

    Linq Group By Multiple Columns

HotTag

Archive