Linq to SQL get updated record in transaction

Draidetar

New Member
I am new to Linq to Sql. I got a scenario. I have two tables. MasterTable and DetailTable table. What I am trying to do is :Inserting new rows in the DetailTable and on base of DetailTable rows I am trying to Update Master in One transaction.Here is my code :\[code\]DBContext context = new DBContext();context.Connection.Open();context.Transaction = context.Connection.BeginTransaction();DetailTable detail = new DetailTable();detail.Amount = 100;var detailTable = context.GetTable<DetailTable>(); // pass in the object with insert on submit // and then submit changesdetailTable.InsertOnSubmit(detail);var result = (from Total in context.MasterTableselect Total).Sum();decimal total = (decimal)result; // This total is not the latest.// UpdateMaster.....// ................context.SubmitChanges();context.Transaction.Commit();\[/code\]Now the problem, I am facing is that I am not getting the latest Sum from MasterTable. Like after inserting new row of amount 100, say I should get 600 but I am getting 500 (Sum rows as if I have not inserted new row). Please let me know if this is possible using Linq to Sql if it is then how or I am trying to achieve something which is not possible.
 
Back
Top