0

Hi before I use to retrieve and manipulate data directly from my DB..but this time I am using Entity Data Model.. I have all the tables in my .edmx file .... I have some queries in my DB for retrieving data but now as I am using Entity Data Model I don't know how to call that procedure in my controller as I am using MVC 3 here can any one tell me how to get the data using my stored procedure or write a Linq query similar to my stored procedure in my controller

Here is my stored procedure:

  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

How do I do this?

0

1 Answer 1

1

The easy way is:

  1. Open your .edmx model in VS designer
  2. Right-click and select "Update Model From Database..." (stuff like that)
  3. Choose your SP from the given dialog and hit "Finish"
  4. In your Controller write:

     var result = new YourEntitiesName().StoredProcedureName();
    
Sign up to request clarification or add additional context in comments.

1 Comment

It works without function import. I don't know the details though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.