我有一个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;
}


谢谢

最佳答案

像“关系修正”这样的东西应该可以工作:

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

关于c# - 将导航属性映射到存储过程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3786493/

10-09 02:34