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

  • Home
  • SEARCH
  • 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 6018039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:12:59+00:00 2026-05-23T03:12:59+00:00

I have to perform a bulk operation bool AddEntitiesX(List<X>) : For each insert of

  • 0

I have to perform a bulk operation bool AddEntitiesX(List<X>):

  • For each insert of X into X_Table (with X_UID as auto-increment ID), I have to insert k-times another entity Y into Y_Table (with X_UID as FK and Y_UID as auto-increment ID), since X contains a list of k–Y entities.
  • Then, for each inserted X, I need to insert also a Z entity in Z_Table (with X_UID as FK and Z_UID as auto-increment ID).

My pseudo-code will look like this:

// cannot use 'TransactionScope' since there are problems with Oracle
// so, prepare SqlTransaction
foreach (X)
{
 //1. call 'InsertX' SP

 foreach (Y in x.ListY)
   //2. call 'InsertY' SP

 //3. call 'InsertZ' SP
}
// commit transaction

How can I retrieve the X_UID from InsertX SP to pass to the next stored procs?

If there is no way, then since I cannot have this big transaction in one stored procedure, how should I model it?

I would like to know best practices to handle this kind of operations from business to data layer using transactions.

Thank you… and please let me know if my question is not clear enough.

  • 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-23T03:13:00+00:00Added an answer on May 23, 2026 at 3:13 am

    One way is to use SCOPE_IDENTITY(), like cdel already suggested. Another way is to use the OUTPUT clause of INSERT

    INSERT INTO table (field, field, ...) 
    OUTPUT INSERTED.ID
    VALUES (@value, @value, ...);
    

    This inserts the record and also produces a result set, which contains the inserted row generated identity value. In C# you read this result set just as if you’d have executed a SELECT, ie. you use ExecuteReader().

    One advantage of using OUTPUT clause is that is the only way it can reliable return multiple row IDs. Say you insert not one, but 100, you can get back the IDs of all 100 inserted rows in a single result set. In case you wonder how to insert 100 rows in one swoop, see Arrays and Lists in SQL Server 2008: Using Table-Valued Parameters.

    Another advantage of using OUTPUT clause is that you can chain two statements into a single one, see Chained Updates.

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

Sidebar

Related Questions

Let's say you have a business logic method that can perform some operation across
I have a utility in my application where i need to perform bulk load
I have to perform a SELECT operation in the DB. Since I want to
I have to perform 3 operations in a windows app as a Transaction. These
I have an application that uses DataTables to perform grouping, filtering and aggregation of
I have coded some JavaScript to perform an ajax call in an asp.net application.
I have a LinkButton that has to postback to perform some logic. Once it
I have several customers where my WinForms app does not perform as well as
I have a few things that I cannot find a good way to perform
I have developed a build system on MSBuild (NET 3.0) and cc.net to perform

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.