In addition to SPROCS, LINQ to SQL also supports both scalar-valued and table-valued user defined functions (UDFs), as well as the
in-line counterpart to both. Once added to your DataContext as a method,
you can use these UDF functions within your LINQ queries.
For example, consider a simple scalar user defined function
called "MyUpperFunction":
Figure 23
We can drag/drop it from the Visual Studio Server Explorer
onto our LINQ to SQL Designer to add it as a method on our DataContext:
Figure 24
We can then use this
UDF function inline within our LINQ expressions when writing
queries against our LINQ to SQL data model (notice it is being used within the
"where" clause below):
VB:
Figure 25
C#:
Figure 26
If you use the LINQ to SQL Debug Visualizer that I blogged about here, you can see how LINQ to SQL transforms the above
expression queries into raw SQL that execute the UDF inside the
database at runtime:
Figure 27