NIRANJAN G NIRANJAN G - 2 years ago 126
C# Question

linq query to update multiple rows

I am trying to update multiple rows using linq. My table structure is as below.

id uploadID Label Value
1 100 docNumber 123
2 100 expiryDate 1/1/2017

My DAL function is as below.

public int updatedocDetails(int upld_id, string docnumber, string expiryDate, string username)


In function i am recieving uploadId(for ex 100) and (docNumber for ex 456 and expiryDate for ex 2/2/2017)

So my resulting table should be

id uploadID Label Value
1 100 docNumber 456
2 100 expiryDate 2/2/2017

Is there anyway I can achieve this by using Linq? thank you in advance

woz woz
Answer Source

Something like this should work:

List<Record> records = (from p in Context.Records
                        where .... // add where condition here
                        select p).ToList();

records[0].Value = 456;
records[1].Value = '2/2/2017';

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download