Reputation: 43
I have table with token, userName, StatusId. Before i insert any row in table for a specific user i would like to check if any rows with active status are there if so update it to inactive.
I am unable to figure out how can i do this in LINQ. Currently iam retreving my values as the query below.
var activeUsers =
(from _users in currentDataContext.Users
where _users.StatusId.Equals(1)
select _session);
Upvotes: 3
Views: 108
Reputation: 14874
users = currentDataContext.Users.Where(o => o.StatusId == 1);
foreach(var item in users)
item.StatusId = 0;
currentDataContext.SaveChanges();
Beware that If you app is multi user then there is a chance that DB has been changed after you queried the database.
Upvotes: 2
Reputation: 6577
Would this work?
currentDataContext.Users.Where(x=> x.StatusId == true).First().StatusId = False;
currentDataContext.SaveChanges();
Upvotes: 0