Hi again,
So I've had a go at this, but am struggling a little to map it into LLBLGen predicates and such.
This is the complete query (with variables and select * for clarity):
select
*
from
Assessment a
where
assessmentdate in
(
select
MAX(AssessmentDate) as latestDate
from
Assessment a2
Join Metric m on a2.MetricID = m.MetricID
where
a2.MetricID = a.MetricID
and m.SpecialityID = @SpecialityID
group by
a2.MetricID
)
and userID = @UserID
and this is what I have in code:
IPredicateExpression subFilter = new PredicateExpression(PredicateFactory.CompareValue(AssessmentFieldIndex.MetricId, ComparisonOperator.Equal, AssessmentFieldIndex.MetricId, "A2"))
.AddWithAnd(PredicateFactory.CompareValue(MetricFieldIndex.SpecialityId, ComparisonOperator.Equal, specialityID));
IRelationCollection relations = new RelationCollection();
relations.Add(MetricEntity.Relations.AssessmentEntityUsingMetricId, "A2");
IGroupByCollection groupBy = new GroupByCollection();
groupBy.Add(AssessmentFields.MetricId);
RelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(
new FieldCompareSetPredicate(AssessmentFields.AssessmentDate,
null,
AssessmentFields.AssessmentDate,
null,
SetOperator.In,
subFilter,
relations,
"A2",
100, //change this try -1 to get it to select all
null,
false,
groupBy))
.AddWithAnd(AssessmentFields.UserId == userID);
any ideas on what's going wrong?
Thanks,
Matt