Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i work linq with store procure and 3 tier archtecure,
but i have a problem,

I use store procdure like:
SQL
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:
XML
public IEnumerable<tbl_admin_category> GetCategoryDetails(int id)
   {


       var v = li.SP_Category_Get(id);

       return v;


   }


XML
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?)
Posted
Updated 12-Mar-13 2:47am
v4
Comments
Zoltán Zörgő 12-Mar-13 8:35am    
What error exactly?
Arun kumar Gauttam 12-Mar-13 8:39am    
Error is:
Cannot implicitly convert type 'System.Data.Linq.ISingleResult<sp_category_getresult>' to 'System.Collections.Generic.IEnumerable<tbl_admin_category>'. An explicit conversion exists (are you missing a cast?)
bbirajdar 12-Mar-13 8:52am    
Now the question is clear. You are returning a single value of type 'tbl_admin_category' from this line of code var v = li.SP_Category_Get(id);, but the return type of the method is a list ie.e IEnumerable<tbl_admin_category>

You must use a appropriate return type in method definition. Try this

public tbl_admin_category GetCategoryDetails(int id)
{

}
Arun kumar Gauttam 12-Mar-13 9:04am    
if i use this then it also produce error:

public ISingleResult<tbl_admin_category> GetCategoryDetails(int id)
{
var v = li.SP_Category_Get(id);
return v;
}

Now The Error is

Cannot implicitly convert type 'System.Data.Linq.ISingleResult<sp_category_getresult>' to 'System.Data.Linq.ISingleResult<tbl_admin_category>'. An explicit conversion exists (are you missing a cast?)
Arun kumar Gauttam 12-Mar-13 9:05am    
i also use your techniq but it not work

1 solution

Correct. This is the exception you should get. The li.SP_Category_Get(id) method won't return IEnumerable<tbl_admin_category> for sure. The result type will depend on your model. So first modify your code (or make a simple console app to test, or even better use LinqPad[^]) so you can run it and place a breakpoint after var v = li.SP_Category_Get(id); and see what type v will get. Use that type as return type for your method.
 
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