2010-01-31 7 views
2

У меня есть класс, который извлекает данные из БД.Связывание таблиц 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

Но мне нужно, чтобы связать ретранслятор с результатами LINQ к SQL таблиц. Что мне делать?

ответ

1

Вместо привязки непосредственно к запросу, попробуйте:

return context.GetTable<Ilan>().ToList(); 
Смежные вопросы