";
As always, the changes are not applied until SubmitChanges is called, sending the changes back to
the database.
Stored Procedures and User-Defined Functions
Just like tables, stored procedures and functions are mapped, and they are mapped by creating class
methods with the StoredProcedure or Function attribute applied, respectively. The best way to learn
this is by example, so get comfy and ready to start writing code. The following examples illustrate how
to call stored procedures and user-defined functions (UDFs) in several scenarios. You will need to have
Visual Studio open as well as SQL Server Management Studio.
Mapping and Calling Stored Procedures
LINQ to SQL supports the mapping and calling of stored procedures via methods defined in your object
model that represent the stored procedure. Methods are designated as stored procedures by applying the
[Function] attribute and any associated [Parameter] attributes. Mapped stored procedures can return
rowsets and take parameters.
Returning a Single Result
In this first example, you will call a stored procedure that returns a single resultset.
Pages:
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372