In the attached code snippet I have a for each loop on a linq result set.
Each loop updates a LocalPrice field and then calls CalculateRowTotals which is a routine in the partial class of the order details linq entity.
CalculateRowTotal simply updates the totals in the row based on the new LocalPrice.
For some reason CalculateRowTotals does not write the totals back to the database... the LocalPrice is changed without issue... whats going on?
thanks
Wing
'Do we have a current order Dim ordHead = (From p In db.bb_order_headers Where p.AccountNo_FK = c.AccountNo And p.OrderStatus = "N").SingleOrDefault If Not (ordHead Is Nothing) Then Dim ordDetails = From p In db.bb_order_details Where p.OrderHeaderId_FK = ordHead.OrderHeaderId Select p For Each rec As bb_order_detail In ordDetails 'For some reason rec.LocalPriceDB = c.GetLocalCurrencyPrice(rec.Price) rec.CalculateRowTotals() Next db.SubmitChanges() End If
No that wouldnt work - CalculateTotal changes a number of other fields in the row - it does not return anything - its defined in the bb_order_details partial class and therefore has access to all other values in that row instance.
In the code, you can see that before 'rec.LocalPriceDB' is set before 'rec.CalculateRowTotals()' is called. The db.SubmitChanges() after the loop seems to update 'rec.LocalPriceDB' without issue. Why would 'rec.LocalPriceDB' work and CalculateRowTotals not work when they are referecing the same object.
CalculateRowTotalsis called several times elsewhere in the app and has no probllems. However thsi is the only time a for each is used to loop through records.
might need to be
rec.somefield = rec.CalculateRowTotals()