I'm using the following code to store a list of connectionID's in a List<string>
:
List<string> connectionIds =
connectedUsers.Where(x => x.UserId == userId).Select(x => x.ConnectionId).ToList();
I need to update the Database to set the connection status to false
when it finds the corresponding ID's. So far, I am using the following code:
if (connectionIds.Any())
{
foreach (string connectionId in connectionIds)
{
Connection curConn = db.Connection.FirstOrDefault(x => x.ConnectionID == connectionId);
if (curConn != null)
curConn.Connected = false;
db.SaveChanges();
}
}
However, this makes a call to the DB for each connection... Is there any simple way to update the connection in an easier process?