Hi guys,
I need to sum related objects values to a custom property of parent object to use as a display property in a datagrid source.
The equivalent SQL query would look like:
SELECT RR.RentReviewID,
RR.ReviewDate,
SUM(RRI.IncomeValue) AS TotalIncome
FROM RentReview RR JOIN
RentReviewIncome RRI ON RR.RentReviewId = RRI.RentReviewId
GROUP BY RR.RentReviewId,
RR.ReviewDate
RentReview object has RentReviewIncome as associated object.
The query I currently execute is:-
var query = Manager.RentReviews
.Where(a => a.Tenancy.tenancyID == tenancyID)
.OrderByDescending(a => a.effectiveFromDate)
.Include("Schedule")
.Include("RentReviewIncomes");
Query(query, callback);
This returns associated RentReviewIncome objects, but where to from there?
I was hoping something like this custom property on the RentReview object might do the trick, but no.
public decimal TotalIncome { get { return (decimal)RentReviewIncomes.Sum(incomeValue); } }