Update in multiview using Linq

95 Views Asked by At

I want to update details using linq to entities. But instead of takin a new aspx page i want to update details in another view. will it work.? and please give the linq to entity update query

1

There are 1 best solutions below

2
On BEST ANSWER

Let us assume:

  1. db is the context of your Database Entity.
  2. Table_name is the name of Table you need to update.
  3. row_id is the value you are using to search for the data in the Table.

To update using linq you need to fetch the record first using the below query:

var data = (from r in db.Table_name
            where r.id == row_id
            select r).FirstOrDefault();

Now to update the values just update them. For example:

data.Name = "Firstname lastname"
data.IsActive = true;
.
.

and so on

After you have updated the values in data you need to Save the changes made by you by this command:

db.SaveChanges();

That's it.