简体   繁体   中英

How filter a dataset based on a nested dataset record count?

我有一个数据集,我想基于数据集类型的字段记录计数来应用过滤器,例如:'NESTED_DATASET_FIELD.RecordCount> 0'

If the dataset comes from a SQL based storage engine, use a select distict query on the joined table with only fields from the master table in the result set. Let the SQL engine do the work for you.

Depending on your situation, you can use:

  1. In OnFilterRecord event you can have:

    Accept := myDataSetField.NestedDataSet.RecordCount>0;

  2. If you have a SQL backend you can use the Exists or Count in order to fetch only the records which you need. Perhaps is the best approach if you are over a network. However I don't know what infrastructure you have.

  3. In OnFilterRecord event you can have:

    Accept := not myDataSetField.IsNull; //Just testing if the DataSet field is empty - which is one of the fastest ways to do it ...but this depends on the structure of your data / dataset etc.

  4. Sometimes is better to have a dedicated field in your DataSet / Table to specify this status because usually getting such info from the nested dataset can be expensive. (One must fetch it at least partially etc.)

  5. Also, for the same considerations (see 4. above) perhaps you can have a Stored Procedure (if your DB backend permits) to get this info.

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM