在填充tableadapter之前进行过滤

发布于 2025-01-21 09:20:24 字数 504 浏览 0 评论 0原文

因此,我有一个数据集来查询Oracle数据库上的表。桌子很大,有350万个条目。但是,在代码后面,我在几百个必要条目上过滤了此表。

AgileDataSet agileDataSet = new AgileDataSet();
AgileDataSetTableAdapters.UserDataTableAdapter userDataTableAdapter = new AgileDataSetTableAdapters.UserDataTableAdapter();
userDataTableAdapter.Fill(agileDataSet.UserData);

var l=agileDataSet.UserData.Where(x=>x.ID==1234);

由于大量条目,fill()方法永远需要。有没有办法在运行时为填充方法添加条件。在数据集设计器中的TableAdapter的SQL语句中添加永久,其中子句不是一个选项,因为我不知道需要哪些元素。

So i have a DataSet to query a table on an Oracle Database. The table is very large and has 3.5 million entries. However later in the code I filter this table on a few hundred entries that are necessary.

AgileDataSet agileDataSet = new AgileDataSet();
AgileDataSetTableAdapters.UserDataTableAdapter userDataTableAdapter = new AgileDataSetTableAdapters.UserDataTableAdapter();
userDataTableAdapter.Fill(agileDataSet.UserData);

var l=agileDataSet.UserData.Where(x=>x.ID==1234);

Due to the large amount of entries the Fill() method takes forever. Is there a way to add a conditions to the fill method at runtime. Adding a permanent WHERE clause to the TableAdapter's SQL Statement in the DataSet Designer is not an option, because I do not know beforehand which elements are needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生戏 2025-01-28 09:20:24

好的,所以我实现了一个黑客的“解决方案”,并为TableAdapter创建了一个新的部分类别。在此类中,我生成了一个改编的fill函数,只要我需要在我的数据表中获取整个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列表作为附加输入,并在其中添加一个条件用于标准填充功能的基本通信文本。

称其看起来像这样:

List<long> c_ics = new List<long>{224,484,966,695,918};
userDataTableAdapter.FillByCICList(agileDataSet.UserData, c_ics);

我相信有一个更好的解决方案,但这就是我到目前为止的一切

Ok so I implemented a hacky "solution" and created a new partial class for the TableAdapter. In this class I generated an adapted Fill-Function to use whenever I need to get a subset of the whole DBTable in my 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;
        }
    }

This function takes a list of c_ics as additional input and adds a where condition to the base commanttext used for the standard fill function.

Calling it would look sth like this:

List<long> c_ics = new List<long>{224,484,966,695,918};
userDataTableAdapter.FillByCICList(agileDataSet.UserData, c_ics);

I am sure that there is a better solution to this, but that is all I got so far

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文