根据关系集合计数过滤 FetchEntityCollection

发布于 2024-07-14 19:36:18 字数 1213 浏览 3 评论 0原文

我目前获取这样的作业集合:

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.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);

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

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

I currently fetch a collection of jobs like this:

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;

where bucket contains lots of predicates e.g.

    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);

The Job entity has a collection of Attachments (via foreign key)

How can I filter the job list to only select jobs with one or more attachments?
I know I could use a in-memory filter (AggregateSetPredicate) via a dynamic view but this will mean I will have to fetch all the jobs in order to get the correct counts, the current fetch has a maximum on the returned count.

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

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

发布评论

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

评论(1

作死小能手 2024-07-21 19:36:18

解决方案是这样做:

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

Solution is to do this:

    bucket.Relations.Add(JobEntity.Relations.AttachmentEntityUsingJobFk);
FieldCompareSetPredicate filteredAttachments;
filteredAttachments = new FieldCompareSetPredicate(JobFields.Id, null,
                                                   AttachmentFields.JobFk, null,
                                                   SetOperator.In, null);
 bucket.PredicateExpression.Add(filteredAttachments);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文