Database Reference
In-Depth Information
10-5. Defining a Custom Function in the Storage Model
Problem
You want to define a custom function inside the model rather than a stored procedure in the database.
Solution
Let's say that you have a database that keeps track of members and the messages they have sent. Figure 10-4 shows
one representation of this database.
Figure 10-4. A simple database of members and their messages
It may be the case that, as an entry-level programmer, you have not been granted access to the database to create
stored procedures. However, being wise and productive, you want to encapsulate the query logic for finding the
members with the highest number of messages into a reusable custom function in the storage model procedure. The
model looks like the one shown in Figure 10-5 .
Figure 10-5. The model for members and their messages
To define the custom function in the storage model, do the following:
Right-click the .edmx file, and select Open With XML (Text) Editor. This will open the
.edmx file in the XML editor.
Add the code in Listing 10-13 into the <Schema> element. This defines the custom function.
1.
 
Search WWH ::




Custom Search