在填充 TableAdapter 之前进行过滤
filtering before filling a TableAdapter
所以我有一个数据集来查询 Oracle 数据库上的 table。 table 非常大,有 350 万个条目。但是稍后在代码中我过滤了这个 table 在几百个必要的条目上。
AgileDataSet agileDataSet = new AgileDataSet();
AgileDataSetTableAdapters.UserDataTableAdapter userDataTableAdapter = new AgileDataSetTableAdapters.UserDataTableAdapter();
userDataTableAdapter.Fill(agileDataSet.UserData);
var l=agileDataSet.UserData.Where(x=>x.ID==1234);
由于条目过多,Fill()
方法需要很长时间。有没有办法在运行时向 fill 方法添加条件。在数据集设计器中向 TableAdapter 的 SQL 语句添加永久 WHERE
子句不是一个选项,因为我事先不知道需要哪些元素。
好的,所以我实施了一个骇人听闻的“解决方案”并为 TableAdapter 创建了一个新的部分 class。在此 class 中,我生成了一个经过改编的 Fill
-函数,以便在我需要在我的 DataTable
中获取整个 DBTable 的子集时使用
partial class UserDataTableAdapter
{
public virtual int FillByCICList(AgileDataSet.UserDataDataTable dataTable, List<long> cics)
{
this.CommandCollection[0].CommandText += String.Format(" WHERE vu.C_IC IN ({0})", String.Join(", ", cics));
this.Adapter.SelectCommand = this.CommandCollection[0];
if ((this.ClearBeforeFill == true))
{
dataTable.Clear();
}
int returnValue = this.Adapter.Fill(dataTable);
this.InitCommandCollection();
return returnValue;
}
}
此函数将 c_ics 的列表作为附加输入,并向用于标准填充函数的基本命令文本添加 where 条件。
调用它看起来像这样:
List<long> c_ics = new List<long>{224,484,966,695,918};
userDataTableAdapter.FillByCICList(agileDataSet.UserData, c_ics);
我确信有更好的解决方案,但这就是我目前所得到的全部
所以我有一个数据集来查询 Oracle 数据库上的 table。 table 非常大,有 350 万个条目。但是稍后在代码中我过滤了这个 table 在几百个必要的条目上。
AgileDataSet agileDataSet = new AgileDataSet();
AgileDataSetTableAdapters.UserDataTableAdapter userDataTableAdapter = new AgileDataSetTableAdapters.UserDataTableAdapter();
userDataTableAdapter.Fill(agileDataSet.UserData);
var l=agileDataSet.UserData.Where(x=>x.ID==1234);
由于条目过多,Fill()
方法需要很长时间。有没有办法在运行时向 fill 方法添加条件。在数据集设计器中向 TableAdapter 的 SQL 语句添加永久 WHERE
子句不是一个选项,因为我事先不知道需要哪些元素。
好的,所以我实施了一个骇人听闻的“解决方案”并为 TableAdapter 创建了一个新的部分 class。在此 class 中,我生成了一个经过改编的 Fill
-函数,以便在我需要在我的 DataTable
partial class UserDataTableAdapter
{
public virtual int FillByCICList(AgileDataSet.UserDataDataTable dataTable, List<long> cics)
{
this.CommandCollection[0].CommandText += String.Format(" WHERE vu.C_IC IN ({0})", String.Join(", ", cics));
this.Adapter.SelectCommand = this.CommandCollection[0];
if ((this.ClearBeforeFill == true))
{
dataTable.Clear();
}
int returnValue = this.Adapter.Fill(dataTable);
this.InitCommandCollection();
return returnValue;
}
}
此函数将 c_ics 的列表作为附加输入,并向用于标准填充函数的基本命令文本添加 where 条件。
调用它看起来像这样:
List<long> c_ics = new List<long>{224,484,966,695,918};
userDataTableAdapter.FillByCICList(agileDataSet.UserData, c_ics);
我确信有更好的解决方案,但这就是我目前所得到的全部