0

こんにちは、DBから直接データを取得して操作するために使用する前に、今回はエンティティデータモデルを使用しています。.edmxファイルにすべてのテーブルがあります。DBにデータを取得するためのクエリがいくつかありますが、現在はエンティティデータモデルを使用しているため、コントローラーでそのプロシージャを呼び出す方法がわかりません。ここでは、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 に答える