I Am Working 3 tier Architecture with linq and store procedure:
I insert and update And Delete Record Successfully,
But When Secting Record From table Then there is an error releted to type casting:
I have used following code at
BLL:
public List<tbl_admin_category> GetCategoryDetails(int id)
{
var v = li.SP_Category_Get(id);
return ((List<tbl_admin_category>)(v));
}
And At aspx.cs page:
var v1 = obj.GetCategoryDetails(0);
gd_cat.DataSource = v1;
gd_cat.DataBind();
And Procedure Is:
ALTER PROCEDURE [dbo].[SP_Category_Get]
(
@id int=0
)
As
SET NOCOUNT ON
if(@id=0)
Begin
Select * From tbl_admin_category
End
else
Begin
Select * From tbl_admin_category
where
id= @id
End
SET NOCOUNT OFF
ERROR Msg IS:
Unable to cast object of type 'SingleResult`1[SP_Category_GetResult]' to type 'System.Collections.Generic.List`1[tbl_admin_category]'.
And If I not Use Store Procedure:
And Use Simple Method In BLL Then It Work Fine:
Like:
public IEnumerable<tbl_admin_category> GetCategoryDetails(int id)
{
var users = from user in li.tbl_admin_categories
select user;
return users.ToList();
}