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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:55:52+00:00 2026-05-25T06:55:52+00:00

So, I’m trying to make a transaction with LINQ to SQL. I read that

  • 0

So, I’m trying to make a transaction with LINQ to SQL. I read that if I use SubmitChanges(), it would create a transaction and execute everything and in case of an exception everything would be rolled back. Do I need to use MULTIPLE SubmitChanges()? I’m using something like this code and it isn’t working because it isn’t saving any data on the first table.. (I need it’s ID for the children table).

If I do use another SubmitChanges() right after the first InsertOnSubmit doesn’t it lose the idea of a transaction?

myDataContext db = new myDataContext();

Process openProcess = new Process();

openProcess.Creation = DateTime.Now;
openProcess.Number = pNumber;

//Set to insert

db.Process.InsertOnSubmit(openProcess);

Product product = new Product();

product.Code = pCode;
product.Name = pName;
product.Process_Id = openProcess.Id;

//Submit all changes at once?

db.SubmitChanges();
  • 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-25T06:55:52+00:00Added an answer on May 25, 2026 at 6:55 am

    The problem is, that the ID of your process is set when the changes are submitted to the database. Because you submit the changes after the line where you assign the process id to the product (product.Process_Id = openProcess.Id;).

    The correct way to do this would be to correctly setup your database with a foreign key from PRODUCT to PROCESS and use the navigation property Process on Product to assign the process to the product.

    The code would look like this:

    myDataContext db = new myDataContext();
    
    Process openProcess = new Process();
    
    openProcess.Creation = DateTime.Now;
    openProcess.Number = pNumber;
    
    Product product = new Product();
    
    product.Code = pCode;
    product.Name = pName;
    product.Process = openProcess;
    
    db.Product.InsertOnSubmit(product);
    db.SubmitChanges();
    

    Because Process is a navigation property of Product, you don’t need to insert the Process. It will be inserted automatically, because you insert the “parent” – the Product.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.