Click here to Skip to main content
15,891,712 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi ,

I want to how to retrive data using store procedure in wcf in json format with linq to sql classes


I want to retrieve store procedure's out put using WCF in JSON format and I am using LINQ to SQL classes.
Posted
Updated 19-Nov-13 22:30pm
v3

Hi,


Six simple steps to use a Stored Procedure in LINQ[^]

When you add Procedure to DBML then its automatically create output class and which you can use as a Data Contract and returned the same data in JSON
 
Share this answer
 
your requirement is you are using Linq To Sql means a DBML file.
and you are having a store procedure on it.
now are executing the storeprocedure and want the output from store procedure


here i am creating a store p
CREATE PROCEDURE Stock.usp_CheckBuyBookByISBN  
 -- Add the parameters for the stored procedure here  
 (  
 @vcISBN varchar(50),  
 @retvalue int=0 output  
 )  
 AS  
 BEGIN  
 SET NOCOUNT ON;  
  DECLARE @return  int   
  SET @return  = (SELECT COUNT(intBUyBAckid) from Stock.BuybackBooks WHERE vcISBN13=@vcISBN AND decPrice>0 )  
  SET @retvalue=@return  
 End  



here i call the storeprocedure with name usp_CheckBuyBookByISBN and it will return a integer a value.


DataClassesDataContext db = new DataClassesDataContext();
int? b = null;
int a = db.usp_CheckBuyBookByISBN("9780199795352", ref b);



this is how we fetch a the output from store procedure using Linq To Sql
..


now you have a wcf service with json format.
for achving this create a function in wcf and decorate it with a Attribute called as WEBGET
like this.

C#
[OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public int GetResult()
    {
DataClassesDataContext db = new DataClassesDataContext();
        int? b = null;
        int a = db.usp_CheckBuyBookByISBN("9780199795352", ref b);
return a;
}



now simply call that function from you website..
Hope this help.....
 
Share this answer
 
Comments
kingsa 20-Nov-13 5:13am    
Thanks for reply , I want to retrive all employee data into json format with help stored procedure in json
Er Daljeet Singh 20-Nov-13 6:22am    
can you tell me what is this "stored procedure in json"
both store procedure and json are two different thing.
so tell us exactly what you want to do...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900