【问题标题】:Filtering FetchEntityCollection based on relationship collection count根据关系集合计数过滤 FetchEntityCollection
【发布时间】:2009-03-11 13:14:55
【问题描述】:

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

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),但这意味着我必须获取所有作业才能获得正确的计数,当前获取的返回计数具有最大值。

【问题讨论】:

    标签: llblgenpro


    【解决方案1】:

    解决方案是这样做:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多