Can any body give me LINQ equivalent of below query

Posted by Sahoo under Others on 12/1/2011 | Points: 10 | Views : 989 | Status : [Member] | Replies : 2
update submenu set submenuvalue = (submenuvalue-1) where menuid=12 and submenuvalue >12.


table name - menu
column name --submenuvalue ,menuid

thank in advance




Responses

Posted by: Arefin on: 12/1/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Sahoo,

You can try with the following code. If you don't understand, plz inform.

DataUsersClassesDataContext dataUsers = new DataUsersClassesDataContext(); 

var user = dataUsers.Users.Single(u => u.AutoID == XXXX); // write your where condition
if (user != null)
{

// set properties

user.Active = active;
user.Name = "MyName";
user.Role = role;

dataUsers.SubmitChanges(); // submit the changes that will update the database.

}


Thanks,
Arefin

Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 12/2/2011 [Member] Bronze | Points: 25

Up
0
Down
Hope this will helps you:
public bool MarkActive(IList<long> UserIdList)
{

IEnumerable<Linq.Infrastructure.Entity.User> userList = from user in context.Users
where UserIdList.ToArray().Contains(user.Id) select user;
foreach (Linq.Infrastructure.Entity.User userObj in userList)
{
userObj.Active = true;
}
context.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
context.Dispose();

}

Batch update is the behavior of ADO.NET and this is not available outside of DataAdapter. LINQ to SQL does not support batch operation.



Best option is SQL Stored Proc.


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response