Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Linq to sql in Call Stored Procedure & return how list of record set in entity

Here i have csp_GetAllRole stored procedure it takes argument and finally i have required return a list of record using List<core.entity.setting> . So in this i have problem in return data how ? So please help me sir....
C#
public List<setting> GetRole(Core.Entity.Setting se)
{
    var sdata = demo.csp_GetAllRole(se.RoleName, se.SortExpression, se.SortDirection);

    return sdata;
}



[Edit member="Tadit"]
Corrected formatting issues.
Added pre tags.
[/Edit]
Posted
v2
Comments
DamithSL 16-Jun-14 3:19am    
update the question with csp_GetAllRole code
keyur_raval 16-Jun-14 3:30am    
USE [MyDemo]
GO
/****** Object: StoredProcedure [dbo].[csp_GetAllRole] Script Date: 06/16/2014 11:21:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--exec csp_GetAllRole '','RoleName','desc'

ALTER PROCEDURE [dbo].[csp_GetAllRole]

@RoleName nvarchar(100),
@SortExpression varchar(20),
@SortDirection varchar(5)
AS
BEGIN
IF ISNULL(@SortDirection , '') = ''
SET @SortDirection ='ASC'
IF ISNULL(@SortExpression , '') = ''
SET @SortExpression ='RoleName'

Declare @SQLQYR varchar(MAX)
SET @SQLQYR = ''
SET @SQLQYR = @SQLQYR +'

select Distinct * into #temp1 from (

select distinct r.RoleName,r.Description from aspnet_Roles r

WHERE
(IsNull(''' + @RoleName + ''','''') = '''' OR r.RoleName like ''%' + @RoleName + '%'')
)as x order by x.RoleName'


SET @SQLQYR = @SQLQYR + ' select *,ROW_NUMBER() over(order by ' + @SortExpression + ' ' + @SortDirection + ') as ROW into #TEMP_RESULT from #temp1 '
SET @SQLQYR = @SQLQYR + ' select *,(Select Max(ROW) From #TEMP_RESULT) as TotalCount from #TEMP_RESULT order by ROW '




EXEC(@SQLQYR)
PRINT(@SQLQYR)

print (@SortExpression)

END
So, what is the exact issue? Have you tried in SQL Management Studio directly by providing parameters?
DamithSL 16-Jun-14 3:37am    
right click on demo.csp_GetAllRole method and go to definition of the method. can you find the return type of the method?
keyur_raval 16-Jun-14 3:39am    
public List<core.entity.setting> GetRole(Core.Entity.Setting se)
{
var sdata = demo.csp_GetAllRole(se.RoleName, se.SortExpression, se.SortDirection);
return sdata;
}

Code how to write menas i want list of all data return

1 solution

Here is your answer,

XML
public List<setting> GetRole(Core.Entity.Setting se)
{
    List<csp_GetAllRole> obj_sp = new List<csp_GetAllRole>();
    obj_sp = demo.csp_GetAllRole(se.RoleName, se.SortExpression, se.SortDirection);

    return obj_sp;
}
 
Share this answer
 

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