locked
How to call Store Procedure? RRS feed

  • Question

  • can anyone explain me steps to create and add store procedure ?  i want to delete some records from database using SP with some parameters in it.

     

     

     

    Monday, October 18, 2010 3:31 AM

Answers

  • Hi mrhammad,

    if you do not install this tool you can not Importfunction.....

    First of all down load this tool EF4FeatureCTP3 791kb this update for net.4.0 up SL4 XSD2 SSDL Or you can write by your self.

    http://www.microsoft.com/downloads/en/details.aspx?FamilyID=AF18E652-9EA7-478B-8B41-8424B94E3F58&displaylang=en

    1. Install EF4FeatureCTP3 then if she does not work restart windows.

    2. Open project with vs 2010

    3. add new item .EDMX file on Entity Model Wizard select Table and SP

    4. Build solution

    5. Right click on table in .edmx pane chose Stored procedure Mapping.

    6. on solution Explorer chose Map browser at store procedure level right click on SP'Name Chose Add Function Import...

    7.0n add function import panel select Entity then chose table then click OK If you want more complicate depend on you

    8. build solution again

    9. Add domainservice class

    10. modifier domainservice

    this.ObjectContext.tbh_Forums_InsertForum(P1,P2,P3,etc);

    Thanks 

     

     

    Saturday, October 23, 2010 9:10 AM

All replies

  • Hi,

    If you use the EF and RIA:

    Add the procedure that you want then from Model Browser right-click on the procedure and choose Add Function Import,

    Then add a service method that calls this function from ObjectContext.

    Monday, October 18, 2010 4:11 AM
  • This Link will explain how you can work with Stored Procedures in Silverlight .

    http://blogs.msdn.com/b/brada/archive/2009/08/24/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-24-stored-procedures.aspx

    I hope that will help you.

    Monday, October 18, 2010 4:16 AM
  • Monday, October 18, 2010 5:47 AM
  • Hi

    Create a simple fuction in your domainservice class. Then create a object of your entity.

    as: yourEntity rntity=new yourEntity();

    entity.ExecuteFunction("procAll", null);  // procAll is the procedure name.
    if want to pass any parameter then use:
    yourEntity rntity=new yourEntity();
    ObjectParameter param=new ObjectParameter("paramName", paramvalue);
    entity.ExecuteFunction("procAll", param); 

    Please mark as answer if its helpfull.

     

    Monday, October 18, 2010 9:40 AM
  • Helps but confusing post, i am still not able to run store procedure.

    Steps are confusing in all post. can anyone explain me here, how to do it? my procedure doesnt return any value. just and delete procedure.

     

     

    Friday, October 22, 2010 3:12 AM
  • EF 4:

    [1] Just drag n drop the sp

    [2] Right click on draged SP and click on "Add Function to Import"

    WCF RIA:

    //[1] Select sp

    public IQueryable<Memo> SelectMemosByMatter_ID(int? matter_ID, string tableName, string name)

    { return his.ObjectContext.SelectMemosByMatter_ID(matter_ID,tableName,name).AsQueryable();}

    //[2] Update sp 

    [Invoke]

    public int UpdateMemos(string TableName, string Name, int? Matter_ID, int? Sequence, string Notes)

    {

    System.Data.Objects.ObjectResult<UpdateMemos_Result> result;

    result = this.ObjectContext.UpdateMemos(TableName, Name, Matter_ID, Sequence, Notes);

    return result.SingleOrDefault().ResultSP;

    }

     //[3] Delete Sp

    public int DeleteNotesByNote_Id(int? Note_ID)

    {

    System.Data.Objects.ObjectResult<DeleteNotesByNote_Id_Result> result;

    result = this.ObjectContext.DeleteNotesByNote_Id(Note_ID);

         

    public int DeleteNotesByNote_Id(int? Note_ID)

    {

    System.Data.Objects.ObjectResult<DeleteNotesByNote_Id_Result> result;

    result = this.ObjectContext.DeleteNotesByNote_Id(Note_ID);

           return result.SingleOrDefault().ResultSP;

    }

     

    }

     In the delete SP..I am returning no of rows deleted using following command at the end of sp "SELECT @@rowcount as ResultSP" and I am getting this value using "return result.SingleOrDefault().ResultSP;" statement.

     

    Friday, October 22, 2010 3:23 AM
  • Error 5 Parameter 'Note_ID' of domain method 'DeleteNotesByNote_Id' must be an entity type exposed by the DomainService. The entity type can be exposed  either directly in a query operation, or indirectly through an association.

    Saturday, October 23, 2010 2:31 AM
  • You can create a class for calling the stored procedure. Make the members as callable through WCF Ria services i.e mark them as DataMember and attributes. Then add these methods as availabel inside domains e

    Saturday, October 23, 2010 3:27 AM
  • OK , can you explain me how do i do that? i have store procedure which takes parameter ID and return no value?

    Saturday, October 23, 2010 4:11 AM
  • Hi mrhammad,

    if you do not install this tool you can not Importfunction.....

    First of all down load this tool EF4FeatureCTP3 791kb this update for net.4.0 up SL4 XSD2 SSDL Or you can write by your self.

    http://www.microsoft.com/downloads/en/details.aspx?FamilyID=AF18E652-9EA7-478B-8B41-8424B94E3F58&displaylang=en

    1. Install EF4FeatureCTP3 then if she does not work restart windows.

    2. Open project with vs 2010

    3. add new item .EDMX file on Entity Model Wizard select Table and SP

    4. Build solution

    5. Right click on table in .edmx pane chose Stored procedure Mapping.

    6. on solution Explorer chose Map browser at store procedure level right click on SP'Name Chose Add Function Import...

    7.0n add function import panel select Entity then chose table then click OK If you want more complicate depend on you

    8. build solution again

    9. Add domainservice class

    10. modifier domainservice

    this.ObjectContext.tbh_Forums_InsertForum(P1,P2,P3,etc);

    Thanks 

     

     

    Saturday, October 23, 2010 9:10 AM