本文介绍了linq与使用3层的商店程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用商店采购和3层Archtecure工作linq,

但我有一个问题,



我使用商店procdure喜欢:

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();







现在问题是:

当我在BLL调用此商店采购然后我需要定义我在显示页面使用的每个coloumn名称,所以我的代码非常冗长,

所以如果有任何方法可以解决此问题我想要:



BLL上的代码是:






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();


    } 





然后在Aspx.cs页面:





and then at Aspx.cs Page:

adminBal obj = new adminBal();

       var v = obj.GetCategoryDetails(0);
       gd_cat.DataSource = v;
       gd_cat.DataBind();











所以我想要那个,

1.就像第一个代码一样(当我在aspx.cs页面上调用Direct SP时,我不需要定义coloum名称)

2.我不想在BLL定义coloum名称;







如果我尝试在BLL喜欢这个:

然后它也会产生错误:






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?)

推荐答案


这篇关于linq与使用3层的商店程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 02:21