none
How to call store procedure has output by Linq RRS feed

  • Question

  • I don't remember how many times I Call store procedure by Linq but not result. Help me !

    This is my store procedure

    CREATE PROCEDURE prc_CheckUserLock<br/>
        @Emp_Account nvarchar(30),<br/>
        @Remaining int OUTPUT<br/>
    AS<br/>
    BEGIN<br/>
      DECLARE @Emp_ReleaseDate SMALLDATETIME<br/>
      SELECT @Emp_ReleaseDate = Emp_ReleaseDate<br/>
          FROM tbl_Employee_Details<br/>
          WHERE Emp_Account = @Emp_Account<br/>
      Set @Remaining = DATEDIFF(SECOND, @Emp_ReleaseDate, GETDATE())<br/>
      return @Remaining<br/>
    END<br/>
    
    

    Code below is error : The best overloaded method match for 'DressShop.MyShopEntities.prc_CheckUserLock(string, System.Data.Objects.ObjectParameter)' has some invalid arguments

     

    MyShopEntities MyShopDB = new MyShopEntities();
    int para = 0;
    remaining = MyShopDB.prc_CheckUserLock("haanh", ref para);
    Thursday, October 28, 2010 1:44 PM

Answers

All replies

  • Hello,

    Please try to add a question mark after int, a code snippet as below:

    int? para = 0;
    remaining = MyShopDB.prc_CheckUserLock("haanh", ref para);

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Friday, October 29, 2010 6:18 AM
  • Thanks Roahn Lou

    I tried it but incorrect. It's warning : Argument 2: cannot convert from 'ref int?' to 'System.Data.Objects.ObjectParameter'

    When I add model of Database, I choose  Add --> New Item... --> Data --> ADO.NET Entity Data Model

    Default name is Model1.edmx and I change to DressShopModel.edmx

    I don't know that is my choose (ADO.NET Entity Data Model) , it is influence to the way call store procedure.

    Hope that some people demo for call prc_CheckUserLock by Linq.

    Please help me

    Saturday, October 30, 2010 8:35 AM
  • I'm sorry for the late reply. I did not mention that this works in linq to sql since you post here (linq to sql forum)

    Hello,

    Please try to add a question mark after int, a code snippet as below:

    int? para = 0;
    remaining = MyShopDB.prc_CheckUserLock("haanh", ref para);

    In Entity framework, you need to specify the output parameters and then retrieve the result. Here is a demo for you, hope it could help:
    http://www.timacheson.com/Blog/2009/jul/entity_framework_stored_procedure_with_output_parameter
    and one more: http://blogs.microsoft.co.il/blogs/gilf/archive/2010/05/09/how-to-retrieve-stored-procedure-output-parameters-in-entity-framework.aspx

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Edited by liurong luo Monday, November 1, 2010 8:38 AM link
    • Marked as answer by liurong luo Wednesday, November 3, 2010 10:39 AM
    Monday, November 1, 2010 8:36 AM