WCF Data Services - neither .Expand or .LoadProperty seems to do what I need

Posted by TomK on Stack Overflow See other posts from Stack Overflow or by TomK
Published on 2010-04-12T22:11:10Z Indexed on 2010/04/12 22:12 UTC
Read the original article Hit count: 390

I am building a school management app where they track student tardiness and absences. I've got three entities to help me in this. A Students entity (first name, last name, ID, etc.); a SystemAbsenceTypes entity with SystemAbsenceTypeID values for Late, Absent-with-Reason, Absent-without-Reason; and a cross-reference table called StudentAbsences (matching the student IDs with the absence-type ID, plus a date, and a Notes field).

What I want to do is query my entities for a given student, and then add up the number of each kind of Absence, for a given date range. I prepare my currentStudent object without a problem, then I do this...

Me.Data.LoadProperty(currentStudent, "StudentAbsences") 'Loads the cross-ref data

lblDaysLate.Text = (From ab In currentStudent.StudentAbsences Where ab.SystemAbsenceTypes.SystemAbsenceTypeID = Common.enuStudentAbsenceTypes.Late).Count.ToString

...and this second line fails, complaining it has no value for an object.

I presume the problem is that while it DOES see that there are (let's say) four absences for the currentStudent (ie, currentStudent.StudentAbsences.Count = 4) -- it can't yet "peer into" each one of the absences to look at its type.

How do I use .Expand or .LoadProperty to make this happen? I tried fiddling with .LoadProperty but it doesn't take a two-level syntax like so...

Data.LoadProperty(currentStudent,"StudentAbsences.SystemAbsenceTypeID") or the like.

Is there some other technique?

© Stack Overflow or respective owner

Related posts about ado-net-dataservices

Related posts about wcf-data-services