Database Reference
In-Depth Information
[EdmFunction("EFRecipesModel", "GetSupervisor")]
public static Supervisor GetSupervisor(TeamMember member)
{
throw new NotSupportedException("Direct calls not supported.");
}
}
The output of the code from Listing 11-8 is as follows:
Using eSQL...
Team members that report up to either
Project Manager Jill Masterson
or Supervisor Steve Johnson
Associate: Nancy Jones
Associate: Stacy Rutgers
Using LINQ...
Team members that report up to either
Project Manager Jill Masterson
or Supervisor Steve Johnson
Associate: Nancy Jones
Associate: Stacy Rutgers
How It Works
In the GetSupervisor() function in Listing 11-7, we need to make three hops through the Manager navigation
property. The first one gets the team lead from the team member, the second one gets the project manager
from the team lead, and the final one gets the supervisor from the project manager. We already created the
GetProjectManager() function in Listing 11-7, so we can leverage that function to simplify the implementation of the
GetSupervisor() function.
We use the treat() eSQL operator to cast an instance of Associate to its concrete type, which is either
ProjectManager or Supervisor. If we didn't use the treat() operator, Entity Framework would raise an exception
complaining that it cannot map the instance of Associate to ProjectManager or Supervisor.
In Listing 11-8, using the GetProjectManager() and GetSupervisor() functions allows us to simplify the code by
hiding all of the traversal through the object graph via the Manager navigation property.
Because we are not returning IQueryable<T> from our model-defined function, we didn't need to provide an
implementation of the stubs we require to use these functions in the LINQ query.
11-5. Returning an Anonymous Type from a
Model-Defined Function
Problem
You want to create a model-defined function that returns an anonymous type.
Solution
Let's say that you have a model for hotel reservations like the one shown in Figure 11-5 .
 
 
Search WWH ::




Custom Search