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 745453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:05:47+00:00 2026-05-14T09:05:47+00:00

I have 2 tables Table1 with columns [BId,Name,Amount] Table2 with columns [CId,BId, ExpenseType,Expense]. BId

  • 0

I have 2 tables Table1 with columns [BId,Name,Amount] Table2 with columns [CId,BId, ExpenseType,Expense]. BId Is the foreign key in Table2.

The Amount field in Table1 is always higher than Expense in Table2. I need to update the values of Amount (increase or decrease) based on value of Expense and I want to do it in single query in LINQ. Eg If the Expense has to be updated with 200, I would decrease(negate) Amount value with 200. If Expense is reduce to 100 then the Amount is increased by a value of 100.

Thanks in advance for any suggestions.

  • 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-05-14T09:05:48+00:00Added an answer on May 14, 2026 at 9:05 am

    You cannot perform updates with one query. You cannot even do that in SQL, let alone in LinQ. What you need here is a transaction.
    Within the transaction, You can load both table records into variables, update their values, and commit the transaction.

    using (var transaction = new TransactionScope()) {
        try {
            record1 = (from r in myDataContext.Table1s where r.BId == myBid select r).FirstOrDefault();
            record2 = (from r in myDataContext.Table2s where r.BId == myBid select r).FirstOrDefault();
    
            // Perform your record updates here
            var oldExpense = record2.Expense;
            record2.Expense = newExpense;
            record1.Amount += (newExpense - oldExpense);
    
            myDataContext.SubmitChanges(); // if an exception occurs here, the transaction is aborted
    
            transaction.Complete(); // commits the transaction
    
        } catch (Exception ex) {
            // TODO: Exception handling
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: table1, table2. Table1 has 10 columns, table2 has 2 columns.
I have two tables: Agents with columns: agentid, name DocumentsRead with columns: agentid, document,
I have three tables, Name - columns Custpackingslipjour(table 1) - (deliverydate, dateclosed,, salesid) Inventrans
I have two tables with a variable amount of columns. (I don't know how
I have three tables specifying important columns below Users(Id, username) Groups(Id, groupname, creator) (creator
I have two tables with similar columns - let's say table A with column
I have 2 tables with some columns and another table that I want its
I have three tables with 5 columns each. They can grow upto 15 rows
i have this three tables. Table: Item Columns: ItemID, Title, Content, NoChange (Date) Table:
I have 3 tables with the following columns : * users : user_id *

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.