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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:47:01+00:00 2026-05-16T07:47:01+00:00

I am using LINQ To SQL and calling stored procedures to insert the new

  • 0

I am using LINQ To SQL and calling stored procedures to insert the new rows.

  1. Does the code below demonstrate an appropriate set of steps?
  2. I want to insert (other fours) only if all four inserts are passed otherwise rollback all four inserts.
public bool InsertNewInquiry(Inquiry inq)
{
    using (var transaction = new TransactionScope())
    {
        using (DataContextDataContext dc = conn.GetContext())
        { 
            foreach (Officer po in inq.Recipients)
            {
                int results1 =  (int)dc.**spOffice_Insert**(po.Id,po.Name).ReturnValue;
            }
            foreach (Lookups tags in inq.Tags)
            {
                int results2 =  (int)dc.**spTags_Insert**(po.Id,po.Name).ReturnValue;
            }

            foreach (Phone phone in inq.Phone)
            {
                int results3 =  (int)dc.**spPhone_Insert**(po.Id,po.Name).ReturnValue;
            }

            int results4 =  (int)dc.spInquiry_Insert(
                            inq.Id
                            ,inq.StatusId
                            ,inq.PriorityId
                            ,inq.Subject).ReturnValue;                  


          if (results1 != 0 && results2 != 0 && results3 != 0 && results4 != 0)
          {
              transaction.Complete();
              return true;
          }
          return false;

           /* old code:
            transaction.Complete();    
            if (results == 0)
                return false;
            else
                return true;  */
        }
    }
}

I have tried the above code, but it does not insert the foreach insert (results1…results3)

Any idea how I can make this work as desired?

  • 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-16T07:47:02+00:00Added an answer on May 16, 2026 at 7:47 am

    Consider a solution where:

    • change the scope of your results
    • if a 0 result is a condition for any of your 3 foreach that you absolutely want to rollback for, don’t increment as shown below. Simply check for 0, and break out of the foreach.
    int res1=0, res2=0, res3=0, res4=0;
    foreach (Officer po in inq.Recipients)
    {
        res1 += (int)dc.**spOffice_Insert**(po.Id,po.Name).ReturnValue;
    }
    foreach (Lookups tags in inq.Tags)
    {
        res2 += (int)dc.**spTags_Insert**(po.Id,po.Name).ReturnValue;
    }
    foreach (Phone phone in inq.Phone)
    {
        res3 += (int)dc.**spPhone_Insert**(po.Id,po.Name).ReturnValue;
    }
    res4 += (int)dc.spInquiry_Insert(inq.Id,inq.StatusId,inq.PriorityId,inq.Subject)
                     .ReturnValue;                  
    
    //no results are zero
    if (res1 != 0 && res2 != 0 && res3 != 0 && res4 != 0)
    {
        transaction.Complete();
        return true;
    }
    return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 485k
  • Answers 485k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No. I would make an adapter that largely forwarded all… May 16, 2026 at 7:49 am
  • Editorial Team
    Editorial Team added an answer The problem is with this statement: [formatter setDateFormat:@"MMM d, YYYY… May 16, 2026 at 7:49 am
  • Editorial Team
    Editorial Team added an answer You are writing to a file called \public\stylesheets\colors.css when you… May 16, 2026 at 7:49 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.