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 (FileAdd New ...
Get ASP.NET 3.5 For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.