I am digging into LINQ–trying to understand basic models (it seems pretty cool to me). The code below is the code to perform before committing an update.
Linq01.Account acc = context.Accounts.Single( pc => pc.AccountID == AccountID ); acc.Name = textboxAccountNameRead.Text.Trim(); context.SubmitChanges();
So far, so good. But what do you do if the Single() method failed–if the account ID wasn’t found?
Thank you!
You should use
SingleOrDefault, if the query does not return a value you can check it against null: