我有一个从数据库检索数据的类。
[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;
}
我通过上面的类绑定数据来自数据库。
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的东西。
我收到此错误:
我找到了关于此错误的很好的解释,它是:
基础数据源必须在以下位置支持ICollection接口
命令网格执行自动分页。 ICollection需要一个
类以实现Count属性。 ArrayList和DataView都
支持该接口,因此您可以将它们用作DataSources。其他类仅支持IEnumerable接口。这使他们
用作数据源,而不用作页面数据源。
SqlDataReader将是此类的示例。 Reference
但是我需要将转发器与linq的结果绑定到sql表。我该怎么办?
最佳答案
与其直接绑定到查询,不如尝试:
return context.GetTable<Ilan>().ToList();
关于c# - 将LinqToSql表绑定(bind)到Repeater,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2171560/