Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8607431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:21:22+00:00 2026-06-12T03:21:22+00:00

I am new to Linq to Sql. I got a scenario. I have two

  • 0

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 :

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 changes
detailTable.InsertOnSubmit(detail);

var result = (from Total in context.MasterTable
select Total).Sum();

decimal total = (decimal)result; // This total is not the latest.

// UpdateMaster.....
// ................

context.SubmitChanges();
context.Transaction.Commit();

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:21:23+00:00Added an answer on June 12, 2026 at 3:21 am

    Try to put the context.SubmitChanges(); above the decimal total = (decimal)result;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Me again! I have a question re. inserting into a sql table using LINQ.
I am new to LINQ to SQL, but have done a lot of database
New to MVC3 Razor - linq to sql having spent some time trying to
I've got this method that returns a Linq-to-SQL query for all the rows in
im really new to linq-to-SQL so this may sound like a really dumb question,
I am quite new with Linq to SQL and MVC but I follow the
We are using Linq-to-SQL with SQL Server as an ORM on our new project.
I'm new at LINQ, searching the net for LINQ samples that mimic SQL's LIKE
I am querying through linq to a SQL Azure database. When a new company
Im new to linq so i still struggle .... I have a collection of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.