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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:21:58+00:00 2026-06-11T05:21:58+00:00

i have two tables realted by 1 – 1 realtion. something like: DOC: Id,SN

  • 0

i have two tables realted by 1 – 1 realtion. something like:

DOC: Id,SN (Id is primary key)
Sub: Id,Name (Id is foreign key)

DOC.Id and Sub.Id are related 1 – 1 as i mentioned

now in business objects i feel the data class as follow:

DOC doc = new DOC();
doc.SN = 1;
Sub sub = new Sub();
sub.Name = "name";
doc.Sub = sub;

using(dbDataContext db = new dbDataContext())
{
   db.DOC.InsertOnSubmit(doc);
   db.SubmitChanges();
   sub.Id = doc.Id;
   db.Sub.InsertOnSubmit(sub);
   db.SubmitChanges();
}

the last SubmitChanges() throw an exception (can’t insert object is already existed)

back to the database i found out that both objects are inserted after executing that code.
is that an implicit transaction or am i doing something wrong

  • 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-11T05:22:00+00:00Added an answer on June 11, 2026 at 5:22 am

    Linq2SQL is persisting the object graph on the first SubmitChanges()

    i.e.

    db.DOC.InsertOnSubmit(doc);
    

    Saves doc, and its child doc.Sub

    This isn’t related to implicit transactions, it is just that when the Parent is attached to the datacontext with InsertOnSubmit(), L2SQL automagically attaches its children as well.

    If you do want an explicit ‘insert’ for the Sub, then don’t assign the Sub to the Doc until after the Doc’s SubmitChanges() (i.e. Insert the doc with a null Sub).

    It is quite difficult to manually detach an object from a DataContext once attached.

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

Sidebar

Related Questions

i have two tables both are related with primary-foreign key ralation and i have
I have two tables that are not related using a foreign key but should
I have two tables related by a composite primary key and one of the
I have two tables, related by a common key. So TableA has key AID
I have two tables in APEX that are linked by their primary key. One
I have two tables in MySQL that are related. I would like to find
I have two tables which are related as HABTM: Groups(id, name) Streams(id, Stream) Connecting
I have these two related tables Client (ClientId, Name) and ClientDescription (ClientDescriptionId, (FK) ClientId,
I have two tables related: DataEntered and Model DataEntered -currentModel Model One DataEntered can
I have two related tables in my database: Page and Tag. One Page can

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.