我将 Simple.Data 与 SQL Server 一起使用,并且我有多种相互独立的方法。在一个表单上,我有多个需要填充的下拉列表,我认为这些可以异步填充。我有一个返回实体列表的存储库。
在我的 Asp.Net 网站上,我一一调用存储库上的方法并将它们绑定到下拉列表这里是示例代码
private void Initialize()
{
LoadTechnologies();
LoadInstallationTypes();
LoadProvinces();
LoadYears();
}
private void LoadTechnologies()
{
ddlTechnologies.DataSource = _GizRepository.GetTechnologies();
ddlTechnologies.DataValueField = "Name";
ddlTechnologies.DataTextField = "Name";
ddlTechnologies.Items.Insert(0, new ListItem("All", "-1"));
ddlTechnologies.DataBind();
}
private void LoadInstallationTypes()
{
ddlInstallationType.DataSource = _GizRepository.GetInstallationTypes();
ddlInstallationType.DataValueField = "Type";
ddlInstallationType.DataTextField = "Type";
ddlInstallationType.Items.Insert(0, new ListItem("Any", "-1"));
ddlInstallationType.DataBind();
}
private void LoadProvinces()
{
ddlProvinces.DataSource = _GizRepository.GetProvinces();
ddlProvinces.DataValueField = "Name";
ddlProvinces.DataTextField = "Name";
ddlProvinces.Items.Insert(0, new ListItem("All", "-1"));
ddlProvinces.DataBind();
}
private void LoadYears()
{
ddlYearFrom.DataSource = _GizRepository.GetYears();
ddlYearFrom.DataValueField = "Year";
ddlYearFrom.DataTextField = "Year";
ddlYearFrom.DataBind();
ddlYearTo.DataSource = _GizRepository.GetYears();
ddlYearTo.DataValueField = "Year";
ddlYearTo.DataTextField = "Year";
ddlYearTo.DataBind();
}
您可以从上面的代码中看到,我所做的只是从存储库中获取一些列表并将它们绑定到下拉列表。我想异步而不是同步执行这些方法,请指导如何完成?