public static void SignOut(User newUser)
{
WorkAchievementsDataContext db = new WorkAchievementsDataContext();
var updateUser = db.Users.First(u => u.ID == newUser.ID);
updateUser.IsLoggedOn = false;
db.SubmitChanges();
}
So entirely make my day!
Isn't that wonderful? Four lines of code and I have successfully updated my database. No connection strings, no stored procedures, it's just there in those four little lines of code! How wonderful. :)
Basically (for those that are new like myself) the lines do the following:
1) Creates an instance of the DataContext from my Linq to Sql Class.
2) Uses a lambda expression to retrieve the user that has an ID matching the one that is passed in.
3) Changes the "IsLoggedIn" field to false in my table.
4) Saves the changes to the database.
Being new at WPF and Linq, I am sure that I will find lots of fun and exciting things to play with, but for now it is time to go home.

0 comments:
Post a Comment