using stored procedures in a LINQ query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silpa
    New Member
    • May 2007
    • 20

    using stored procedures in a LINQ query

    Hi,
    Suppose if there are 10 records in employee table.

    I have a stored procedure named GetEmpCount which returns employee count. (i.e., The answer is 10).

    i.e., Select count(*) from employee
    --------------------------------------------------------------------------------------------------------------------
    I have drag and dropped GetEmpCount stored procedure on to the LINQ dbml designer.
    Now I am writing a method like as follows.

    public int GetEmployeeCoun t()
    {
    DatabaseContext db=new DatabaseContext ();

    int result =db.GetEmpCount ();

    return result;
    }

    The result should be 10.

    But when I build the classlibrary, I am getting error like
    Error Cannot implicitly convert type 'System.Data.Li nq.ISingleResul t<GetEmpCountRe sult>' to 'int'


    I request you to help me in this regard.

    Thanks,
    Silpa
  • Pravat Mishra

    #2
    Try using

    int result = db.GetEmpCount( ).ReturnValue;
    You may have to cast as well.. in that case try
    int result = (int)db.GetEmpC ount().ReturnVa lue;

    Comment

    Working...