Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get it all done in one statement you need to join Enrollments and Commissions and then group by the Tutor.</p> <p>This first example uses Query Syntax like you are using:</p> <pre><code> IEnumerable&lt;TutorCommission&gt; tutorsCommissions = from enrollment in enrollments // Take the enrollments join tutorsCommissionPercentage in tutorCommissionPercentages // Join with the tutor's commission percentages. on enrollment.TutorNoID equals tutorsCommissionPercentage.TutorNoID group enrollment by new { enrollment.TutorNoID, tutorsCommissionPercentage.CommissionPercentage } into enrollmentsAndCommissionByTutor // group enrollments and commission by the tutor select new TutorCommission { TutorNoID = enrollmentsAndCommissionByTutor.Key.TutorNoID, // the grouping which is the tutor CommissionAmount = (long) enrollmentsAndCommissionByTutor.Sum(e =&gt; e.MonthlyFee * enrollmentsAndCommissionByTutor.Key.CommissionPercentage) }; </code></pre> <p>This second example uses Method Syntax which is a little more intuitive for this operation</p> <pre><code> IEnumerable&lt;TutorCommission&gt; tutorsCommissionsAlt = enrollments // Take the enrollments .GroupJoin( // This will group enrollments by the tutor tutorCommissionPercentages, // Join with the tutor's commission percentages. e =&gt; e.TutorNoID, // Use tutorNoID for left Key tcp =&gt; tcp.TutorNoID, // ... and right key (e, tcp) =&gt; new TutorCommission // Create entry which is the tutor and his total commission { TutorNoID = e.TutorNoID, CommissionAmount = (long) tcp.Sum(c =&gt; c.CommissionPercentage * e.MonthlyFee) }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload