日期:2014-05-20  浏览次数:20776 次

两张的表的linq语句到底怎么写???
http://topic.csdn.net/u/20110623/20/df62a36c-da6a-4270-9410-92c5fd6eaef0.html?seed=1079323768&r=74025081#r_74025081
上一个帖子有点乱了,整理一下
从新建立了两张表
YSYS_DYTPImg表


YSYS_Type表


前台
C# code

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
      
        <ItemTemplate>
           <table><tr>
           <td style="width:40%">
               <asp:Label ID="lblImg_id" runat="server" Text='<%#Eval("img_id") %>' Visible="false"></asp:Label><img  src='../<%#Eval("img_url") %>' height="20px"/></td>
           <td style="width:10%">

<%#Eval("pic_type") %>
//这个是YSYS_Type当中的字段,其他字段都是YSYS_DYTPImg当中的字段

</td>
           <td><%#Eval("img_name") %></td>
           <td style="width:10%">
               <a href='<%#Eval("img_id","DetailDYTPImg.aspx?img_id={0}") %>'>修改</a></td>
           
                      </tr></table>
        
        </ItemTemplate>
        </asp:Repeater>
  <webdiyer:AspNetPager ID="aspPages" runat="server" HorizontalAlign="Center" 
                        onpagechanging="aspPages_PageChanging">
        </webdiyer:AspNetPager>



后台到底怎么写???
C# code

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            //  YSYSDataContext ysys = new YSYSDataContext();//这个是linq to sql自动生成的代码
            //  IList<YSYS_DYTPImg> list = ysys.YSYS_DYTPImg.ToList();
            //aspPages.RecordCount = list.Count;
            //PagedDataSource pd = new PagedDataSource();
            //pd.DataSource = list;
            //pd.AllowPaging = true;
            //pd.PageSize = this.aspPages.PageSize;
            //pd.CurrentPageIndex = 0;
            //this.Repeater1.DataSource = pd;
            //this.Repeater1.DataBind();
        }
    }
  protected void aspPages_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {

    }



------解决方案--------------------
晕,居然忘了 on
 var list = from i in ysys.YSYS_DYTPImg
join t in ysys.YSYS_Type
on i.Pic_Id equals t.Pic_Id
select new {i.ImgId, i.Img_Url, i.Pic_Id, i.Img_Name, t.Pic_Type}
------解决方案--------------------
C# code
  YSYSDataContext ysys = new YSYSDataContext();
          // IList<YSYS_DYTPImg> list = ysys.YSYS_DYTPImg.ToList();
           var list = (from i in ysys.YSYS_DYTPImg
                      join t in ysys.YSYS_Type
              on i.Pic_Id equals p.Pic_ID
                      select new Temp
            {
                ImgId=i.ImgId, 
                Img_Url=i.Img_Url, 
                Pic_Id=i.Pic_Id, 
                Img_Name=i.Img_Name,
                Pic_Type= t.Pic_Type
            }).ToList()
           
           
           aspPages.RecordCount = list.Count();
           PagedDataSource pd = new PagedDataSource();
           pd.DataSource = list;
           pd.AllowPaging = true;
           pd.PageSize = this.aspPages.PageSize;
           pd.CurrentPageIndex = 0;
           this.Repeater1.DataSource = pd;
           this.Repeater1.DataBind();


public class Temp
{
  public int ImgId{get;set;}
  public string Img_Url{get;set;}
  public int Pic_Id{get;set;}
  public string Img_Name{get;set;}
  public string Pic_Type{get;set;}
}