将导航属性映射到存储过程

时间:2010-09-24 11:16:13

标签: c# .net entity-framework

我有一个Application课程。实体框架创建了一个名为Assistants的导航属性。当我运行我的Web应用程序时,框架会为我填充Assistants

我写了一个名为GetAssistantsByApplicationID的存储过程。我需要将此存储过程映射到Assistants属性并将其传递给applicationID以返回该特定应用程序的助手。

我该怎么做?我这样做的方法是否正确?

以下是我的存储库类中用于获取特定应用程序的代码:

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

   return application;
}

由于

1 个答案:

答案 0 :(得分:3)

这样的事情应该起作用,因为有一种叫做“关系修复”的东西:

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;
}