Ch2 Viewstate implementation.
I have a query regarding the chapter 2 implementation of deleting records from the database. I'm critiquing the code as located on the wrox website, for chapter 2. Additionally to make it functional I added the LINQ/SQL dbml to interact with a MS SQL 2005 express server.
During the page_load event, the following linq query pulls in a record from the database:
ENTUserAccount userAccount = db.ENTUserAccounts.Single(ua =>
ua.WindowsAccountName == @âVARALLO1\VaralloMadisonâ);
However, if you click the delete function:
userAccount.ENTUserAccountId =
Convert.ToInt32(ViewState["ENTUserAccountId"]);
db.ENTUserAccounts.DeleteOnSubmit(userAccount);
This will delete the VaralloMadison entry from the table, as expected.
If you immediately click the INSERT button, this will cause a Page_load event. This is requested on page 35, and pasted below:
"6. Run the project again and click the Delete button on the Default.aspx page to get rid of the
second record.
7. Click the Insert button to insert the record."
However, because the page_load event contains a LINQ query hardcoded that requests a deleted user account you will get an InvalidOperationException because the userAccount LINQ will contain no results.
Am I doing something wrong? I'm slightly confused.
|