I need to detect the entities in the joins, sub clauses and joins in the sub clauses in order to decide whether to add the predicate or not. I am looking for an object in the RelationsToUse collections that would give the entity name and the ability to add a predicate to it, but I don't see it.
Is there source code I can work through to try and see how to do this? Or are there any examples I could read?
UPDATED with example:
Here is a typical example of a Linq statement that I would add a predicate:
var q =
(from a in metaData.RegulationBase
join a1 in metaData.IndustryRegulation on a.RegID equals a1.RegID
where a1.IndCode == 1
&& metaData.RegulationQn.Any(a2=>a2.RegID == a.RegID)
select a)
.WithPath(
a =>
a.Prefetch<RegulationTextEntity>(b => b.RegulationText)
.Prefetch<RegulationHeadingEntity>(c => c.RegulationHeading)
.SubPath(c1=>c1.Prefetch<HeadingBaseEntity>(c2=>c2.Heading)
.SubPath(c3=>c3.Prefetch<HeadingSetCodeEntity>(c4=>c4.HeadingSetCode)))
.Prefetch<RegulationMonitoringReportEntity>(d => d.RegulationMonitoringReports)
.SubPath(e => e.Prefetch<TopicBaseEntity>(f => f.TopicBase)));
return q as IQueryable<T>;
I have already achieved this with the CollectionToFetch and PrefetchPathToUse collections thanks to an earlier forum answer linked above.
The join and the exists sub clause both need && a2.NewResearchDate == ResearchDateFilter to be added also if ResearchDateFilter is not null.
I could go through all our existing application code, modify it to add the predicate where necessary, add tests, and it would work. I am trying to do this in the adapter to avoid that considerable effort on our existing code base and to keep our applications simple even though we are complicating the way data is selected.
Here is what I want to simulate on the above Linq statement:
var q =
(from a in metaData.RegulationBase
join a1 in metaData.IndustryRegulation on a.RegID equals a1.RegID
where a1.IndCode == 1
&& a1.NewResearchDate == ResearchDateFilter // add this line
&& metaData.RegulationQn.Any(a2=>a2.RegID == a.RegID
&& a2.NewResearchDate == ResearchDateFilter // add this line
)
select a)
.WithPath(
a =>
.SubPath(c1=>c1.Prefetch<HeadingBaseEntity>(c2=>c2.Heading)
.SubPath(c3=>c3.Prefetch<HeadingSetCodeEntity>(c4=>c4.HeadingSetCode)))
a.Prefetch<RegulationTextEntity>(b => b.RegulationText)
.Prefetch<RegulationHeadingEntity>(c => c.RegulationHeading) .Prefetch<RegulationMonitoringReportEntity>(d => d.RegulationMonitoringReports)
.SubPath(e => e.Prefetch<TopicBaseEntity>(f => f.TopicBase)));
return q as IQueryable<T>;
Of course, not shown above is the possibility that nested sub clauses in the CollectionToFetch and PrefetchPathToUse collections might also need this additional filtering.