views:

19

answers:

1

Hi,

I have any application class. Entity framework created a navigation property called Assistants. When I run my web application Assistants is populated for me by the framework. I wrote a stored procedure called GetAssistantsByApplicationID. I need to map this stored procedure to the Assistants property and pass it the application ID to bring back the assistants for that specific application. How would I do this? Am I doing it the correct way?

Here is my code from my repository class for getting the specific application:

public Application GetApplicationByID(int applicationID)
{
   var application =
      (from a
      in context.GetApplicationByID(applicationID)
      select a).FirstOrDefault();

   return application;
}

Thanks

+1  A: 

Something like this should work because of something called 'Relationship Fixup':

public Application GetApplicationAndAssistantsByApplicationID(int applicationID)
{
   var application =
      (from a
      in context.GetApplicationByID(applicationID)
      select a).FirstOrDefault();

   // call your other stored procedure...
   var assistants = context.GetAssistantsByApplicationID(applicationID)
                           .ToArray();
   // as the assistants are materialized they will automatically show up
   // in application.Assistants too.

   return application;
}
Alex James