2010-01-31 5 views
2

DB에서 데이터를 가져 오는 클래스가 있습니다.LinqToSql 테이블을 리피터에 바인딩

[Table(Name = "Ilanlar")] 
public class Ilan 
{ 

    [Column(Name="ilan_id" ,IsPrimaryKey = true)] 
    public int M_ilan_id; 

    [Column(Name="refVerenUser_id")] 
    public int M_refVerenUser_id; 
} 

데이터 바인딩은 위의 클래스를 통해 db에서 제공됩니다.

private void ItemsGet() 
    { 
     PagedDataSource objPds = new PagedDataSource(); 
     objPds.DataSource = f_IlanlariGetir(CurrentPage); 
     objPds.AllowPaging = true; 
     objPds.PageSize = 3; 

     objPds.CurrentPageIndex = CurrentPage; 

     rptIlanlar.DataSource = objPds; //rptIlanlar = asp:Repeater 
     rptIlanlar.DataBind(); 
    } 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     ItemsGet(); 
    } 

    private System.Collections.IEnumerable f_IlanlariGetir(int p) 
    { 
     Context context = new Context(DAO.dbYaban.ConnectionString); 

     return context.GetTable<Ilan>(); 
    } 

결과는 IEnumerable이지만 DataSet과 같은 것이 필요합니다. 나는이 오류에 대한 좋은 설명을 발견

Cannot compute Count for a data source that does not implement ICollection.

, 그것이 : 는이 오류 받고 있어요

The underlying DataSource has to support the ICollection interface in order for the grid to perform automatic paging. ICollection requires a class to implement a Count property. ArrayList and DataView both support the interface, so you could use them as DataSources.Other classes only support the IEnumerable interface. This allows them to be used as a DataSource but not as a paged data source. SqlDataReader would be an example of such a class. Reference

을하지만 난 SQL 테이블에 LINQ의 결과와 중계기를 결합해야합니다. 어떻게해야합니까?

답변

1

오히려 쿼리에 직접 결합보다, 시도 :

return context.GetTable<Ilan>().ToList();