根据关系集合计数过滤FetchEntityCollection

时间:2009-03-11 13:14:55

标签: llblgenpro

我目前正在抓取这样的工作集合:

jobs = new EntityCollection<JobEntity>(new JobEntityFactory()); 

var bucket = GetJobsBucket(filter);

var tempContext = new Context();
tempContext.Add(jobs);
var sorter = new SortExpression(JobFields.Id | SortOperator.Descending);

adapter.FetchEntityCollection(jobs, bucket, maxCount, sorter, JobListPrefetchPath(false));

filter.TotalMatchesCount = adapter.GetDbCount(new JobEntityFactory().CreateFields(), bucket, null, false);
filter.ReturnedMatchesCount = jobs.Count;

tempContext.Clear();

return jobs;

其中bucket包含许多谓词,例如

    bucket.Relations.Add(JobEntity.Relations.JobTypeEntityUsingJobTypeFk);
    bucket.Relations.Add(JobTypeEntity.Relations.JobTypeCategoryEntityUsingCategoryFk);   
    var fieldCompareValuePredicate = new FieldCompareValuePredicate(JobTypeCategoryFields.Filter, null,
                    ComparisonOperator.Equal, filter.JobCategory) { CaseSensitiveCollation = true };                        
    bucket.PredicateExpression.Add(fieldCompareValuePredicate);

Job实体有一组附件(通过外键)

如何过滤作业列表以仅选择包含一个或多个附件的作业? 我知道我可以通过动态视图使用内存过滤器(AggregateSetPredicate),但这意味着我必须获取所有作业以获得正确的计数,当前提取在返回的计数上具有最大值。

1 个答案:

答案 0 :(得分:2)

解决方案是这样做:

    bucket.Relations.Add(JobEntity.Relations.AttachmentEntityUsingJobFk);
FieldCompareSetPredicate filteredAttachments;
filteredAttachments = new FieldCompareSetPredicate(JobFields.Id, null,
                                                   AttachmentFields.JobFk, null,
                                                   SetOperator.In, null);
 bucket.PredicateExpression.Add(filteredAttachments);