i work linq with store procure and 3 tier archtecure,
but i have a problem,
I use store procdure like:
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
When i use this procedure direct at code behind:
Then it will be very easy like:
LinqConnectionDataContext li = new LinqConnectionDataContext();
var v = li.SP_Category_Get(0);
gd_cat.DataSource = v;
gd_cat.DataBind();
Now the Problem is:
when i call this store procure at BLL then i need to define every coloumn name which i use at display page, so my code is very lengthy,
so i want that if there are any method for removing this problem:
Code On BLL is:
public IEnumerable<tbl_admin_category> GetCategoryDetails(int id)
{
LinqConnectionDataContext li = new LinqConnectionDataContext();
var v = li.SP_Category_Get(id);
return (from c in v
select new tbl_admin_category()
{
id = c.id,
category = c.category,
category_img = c.category_img
}
).ToList();
}
and then at Aspx.cs Page:
adminBal obj = new adminBal();
var v = obj.GetCategoryDetails(0);
gd_cat.DataSource = v;
gd_cat.DataBind();
so i want that,
1. just like first code(when i call Direct SP at aspx.cs page,and i don't need to define coloum name)
2. i dont want to define coloum name at BLL;
And If I try at BLL like This:
Then it also produce Error:
public IEnumerable<tbl_admin_category> GetCategoryDetails(int id)
{
var v = li.SP_Category_Get(id);
return v;
}
Error is:
Cannot implicitly convert type 'System.Data.Linq.ISingleResult' to 'System.Collections.Generic.IEnumerable<tbl_admin_category>'. An explicit conversion exists (are you missing a cast?)