Database Reference
In-Depth Information
For the LINQ query, we select from the Employees entity set and project onto an anonymous type containing the
Name and Age members. We set these members to the result of invoking our FullName() and Age() functions. As seen
in the previous recipes in this chapter, we need to define the corresponding CLR methods. Because we are returning
scalar values, these methods are never called and are used only for their signatures. The implementation of these
methods reflects this.
We could have created read-only properties in a partial declaration of our Employee entity to implement the
full name and age calculations. However, this would force the evaluation of these methods each time the entity is
retrieved. With model-defined functions, we perform the calculations only when needed.
11-4. Calling a Model-Defined Function from
a Model-Defined Function
Problem
You want to use a model-defined function in the implementation of another model-defined function.
Solution
Suppose that we have the model shown in Figure 11-4 , representing the types of associates in a company along with
their reporting structure
Figure 11-4. A model representing the associate types in a company together with the reporting association
In our fictional company, team members are managed by a team leader. Team leaders are managed by project
managers. Supervisors manage project managers. Of course, there could be many other associate types, but for
simplicity we'll stick with just these few.
If we wanted to return all of the team members for a given project manager or supervisor, we would need to
drill down through the project managers and team leaders to get to the team members. To hide the complexity of
navigating through these layers, we can create model-defined functions that allow easier and more direct access to
these navigation properties.
 
Search WWH ::




Custom Search