gpt4 book ai didi

c# - 将 LinqToSql 表绑定(bind)到 Repeater

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:58 25 4
gpt4 key购买 nike

我有一个从数据库中检索数据的类。

[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;
}

我通过上面的类绑定(bind)来自数据库的数据。

    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 的结果绑定(bind)到 sql 表。我该怎么办?

最佳答案

与其直接绑定(bind)到查询,不如尝试:

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

关于c# - 将 LinqToSql 表绑定(bind)到 Repeater,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2171560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com