LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures)
page 9 of 11
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 47788/ 68

Supporting User Defined Functions (UDFs)

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


View Entire Article

User Comments

Title: Programmer   
Name: Alexander
Date: 2012-11-08 4:51:26 PM
Comment:
Your Figure or pictures don't show up
Title: Use Teporary table   
Name: Ashok Kumar
Date: 2011-07-16 3:28:51 AM
Comment:
if we are fetching the combination of table order and product form database then structure of the newly table will not be match with the mapped table order or price details due to column how to handle this






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 1:22:54 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search