0

嗨,在我直接从我的数据库中检索和操作数据之前。但这次我使用的是实体数据模型。我的.edmx文件中有所有表......我的数据库中有一些用于检索数据的查询,但现在因为我使用的是实体数据模型,所以我不知道如何在我的控制器中调用该过程,因为我在这里使用 MVC 3,任何人都可以告诉我如何使用我的存储过程获取数据或编写类似于我存储的 Linq 查询我的控制器中的程序

这是我的存储过程:

  ALTER procedure [dbo].[ProjectReports]
   (
    @ProjectID int,
    @ReleasePhaseID int
   )
   as
   begin
   select distinct projectName,ReleasePhase,
   (Select  COUNT(1) from Bugs where ProjectId=a.ProjectId and           
     ReleasePhaseID=a.ReleasePhaseID and
     bugid in (select BugID from BugHistory where [status]='New')) as Newbugs,
     (Select  COUNT(1) from Bugs where ProjectId=a.ProjectId and    
     ReleasePhaseID=a.ReleasePhaseID and
     bugid in (select BugID from BugHistory where [status]='Assigned')) as  
     Assignedbugs,
     (Select  COUNT(1) from Bugs where ProjectId=a.ProjectId and  
     ReleasePhaseID=a.ReleasePhaseID and
     bugid in (select BugID from BugHistory where [status]='Fixed')) as Fixedbugs,
      (Select  COUNT(1) from Bugs where ProjectId=a.ProjectId and
       ReleasePhaseID=a.ReleasePhaseID and
     bugid in (select BugID from BugHistory where [status]='Re-Opened')) as 
Reopenedbugs,
    (Select  COUNT(1) from Bugs where ProjectId=a.ProjectId and 
     ReleasePhaseID=a.ReleasePhaseID and
     bugid in (select BugID from BugHistory where [status]='Closed')) as Closedbugs,
     (Select  COUNT(1) from Bugs where ProjectId=a.ProjectId and  
     ReleasePhaseID=a.ReleasePhaseID and
     bugid in (select BugID from BugHistory where [status]='Deffered')) as Defferedbugs,
     (Select  COUNT(1) from Bugs where ProjectId=a.ProjectId and  
      ReleasePhaseID=a.ReleasePhaseID and
      bugid in (select BugID from BugHistory where [status]='Not a Bug')) as NotaBug
      from Bugs a
      inner join Projects p on p.ProjectId=a.ProjectId
      inner join ReleasePhase Rp on rp.ReleasePhaseID=a.ReleasePhaseID
      where a.ProjectId=@ProjectID and a.ReleasePhaseID=@ReleasePhaseID
     end

我该怎么做呢?

4

1 回答 1

1

简单的方法是:

  1. 在 VS 设计器中打开您的 .edmx 模型
  2. 右键单击并选择“从数据库更新模型...”(类似的东西)
  3. 从给定的对话框中选择您的 SP 并点击“完成”
  4. 在你的控制器中写:

     var result = new YourEntitiesName().StoredProcedureName();
    
于 2012-08-18T08:31:28.247 回答