title: LightSwitch Linq To Entities query problem !
body: <p>I'm very new to Linq and Entities Framework. I'm trying to create a WCF RIA Service into a LightSwitch Orders Management application I'm creating. I've already created 7 or 8 queries using Linq (with lot of headaches) but I succeded. Now I need to create a query who gets TotalSales and TotalExpenses by month by using three tables :</p>
  
  <p>DetailsVentes (SaleDetails) composed of : DateOfOrder, Quantity, UnitPrice, Total.... etc
  DetailsAchat (PurchaseDetails) composed of the same fields
  Charges (Expenses) composed of : DateOfExpense, ExpenseType, Cost....etc</p>
  
  <p>Now I want to have a query that finds the Net Income per month (income=TotalSales-TotalPurchases-TotalExpenses)</p>
  
  <p>I tried this query</p>
  
  <pre><code>      Return From od In Me.Context.DetailsVentes
                  From od2 In Me.Context.DetailsAchats
                     From od3 In Me.Context.Charges
                Group By Month = od.Vente.DateCommande.Month, Year = od.Vente.DateCommande.Year
                Into g = Group
                Select New TCR With {.Month = Month, .Year = Year, 
  .MonthYearString = Month &amp; "/" &amp; Year, 
  .TotalVentes = g.Sum(Function(s) (s.od.PrixUnitaire * s.od.Quantité)), 
  .TotalAchats = g.Sum(Function(s) (s.od2.PrixAchat * s.od2.Quantité)), 
  .TotalCharges = g.Sum(Function(s) (s.od3.Cout))}
  </code></pre>
  
  <p>Where Vente is Sale (Order) and DetailVentes is OrderDetails
  Achat is Purchase, and DetailAchat PurchaseDetail
  a Charge is an Expense.</p>
  
  <p>The Problem is I got weird results. All values (TotalVentes, TotalAchats, TotalCharges) are multiplicated by 13 !</p>
  
  <p>For eg if I have 10 000 USD totalSales for June 2011, this query returns 130 000 USD !</p>
  
  <p>I'm really stuck 4 days trying to get the correct query.</p>
  
  <p>I repeat I'm new to Linq :p</p>
  
  <p>Thank you very much. </p>
  
  <p>Edit : I tried @Jason advice I did this :</p>
  
  <pre><code>Return From c In Me.Context.Charges
                           Join v In Me.Context.DetailsVentes On c.DateCharge.Month Equals v.Vente.DateCommande.Month And c.DateCharge.Year Equals v.Vente.DateCommande.Year
                   Join a In Me.Context.DetailsAchats On c.DateCharge.Month Equals a.Achat.DateCommande.Month And c.DateCharge.Year Equals a.Achat.DateCommande.Year
   Group By month = c.DateCharge.Month, Year = c.DateCharge.Year
                   Into g = Group
  Select New TCR With {.Month = month, .Year = Year, .MonthYearString = "", .TotalAchats = g.Sum(Function(c) (c.a.Quantité * c.a.PrixAchat)), .TotalCharges = 45000, .TotalVentes = 250000, .TCRSingle = 0}
  </code></pre>
  
  <p>And results are still very weird (very high) ! Any exemple I can follow ??</p>
  
  <p>Thank you.</p>