New Posts New Posts RSS Feed: object custom property
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

object custom property

 Post Reply Post Reply
Author
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post Topic: object custom property
    Posted: 19-May-2010 at 1:27pm
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); } }
 
Back to Top
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post Posted: 21-May-2010 at 4:04pm
OK I got it;
 
The partial class RentReview generated by DevForce allowed me to include a custom propertry (TotalIncome) and business rule as per below;
 
public decimal TotalIncome { get { return getIncomes(); }}
 
private decimal getIncomes()
{
   decimal totalIncome = 0;
   foreach(RentReviewIncome income in RentReviewIncomes)
   {
      totalIncome = totalIncome + (decimal)income.incomeValue;
   }
   return totalIncome;
}
 
As its in the partial class, DevForce won't overwrite the rule on each subsequent regeneration.
RentReviewIncomes is the collection of associated entities of the main RentReview object.
 
Very cool for me, maybe very obvious for hardened developers...
 
Rgds
BigFish
 
Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 21-May-2010 at 4:32pm
Sorry not to get back to you quicker, but do be aware that the solution you've shown above depends absolutely on the required RentReviewIncomes being in cache at the time the TotalIncome property is accessed. In the asynchronous environment of Silverlight, if they're not there (already), the calculation will simply yield 0.

Back to Top
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post Posted: 21-May-2010 at 5:27pm
Thanks, good point.  Will keep that in mind while working with the app as a user does to determine if we hit that issue....  much appreciated.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down