8.5. Updating Data with a LINQ Query
LINQ to SQL does more than just select data for viewing: It selects it for updates as well. You use the query to get a subset of the data (maybe a subset with just one item) and then loop through the item(s) to do updates. In this section, you add multiple exclamation marks (!) to some items and view the results.
|
8.5.1. Exclaiming with an Extension method
When you type in Code view (see Figure 8-6), you've no doubt seen IntelliSense pop up all those interesting functions like ToLower(), ToUpper(), and ToExclaim(). Okay, maybe you haven't seen ToExclaim() yet in IntelliSense, but you're about to!
Figure 8-6. IntelliSense for the extension method ToExclaim().
Extension methods let you tack on functions of your own. The only catch is that the extension code must be wrapped in a Visual Basic Module, not in the .aspx page itself. Follow these steps to create the ToExclaim() extension method:
In your project's App_Code folder, add a new text file named extmodule.vb (File
Add New ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access