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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:44:15+00:00 2026-05-19T05:44:15+00:00

Hello I have a table that has an id field and a parentid field.

  • 0

Hello I have a table that has an “id” field and a “parentid” field. Both fields are required so you can’t insert null into a parentid column to mark it as a “root” to the hierarchy. I’m having an issue with linq where when I create a new “root” I have to put in a dummy parentid until I know the id of the new root, then I have to updated the parentid field with the correct id and save it again. This seems silly, but I haven’t found a better way to accomplish this yet?

TableWithHeirachy xobj = new TableWithHeirachy();
xobj.property1 = "test";
db.TableWithHeirachy.InsertOnSubmit(xobj);
db.SubmitChanges();
xobj.parentid = xobj.id;
db.SubmitChanges();

This seems really bad. Please tell me there is a better way!

  • 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-19T05:44:17+00:00Added an answer on May 19, 2026 at 5:44 am

    A SQL Statement won’t know the future ID of the row it’s about to insert, until the insert has completed.

    So, either continue as you are now – or instead use special values to indicate root records (null, -1, etc).

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

Sidebar

Related Questions

I have something similar to that: <table> <tr> <td>Hello,<br/>World!</td> </tr> </table> Both lines Hello,
I have a table that has several columns. The value of one column is
Hello i have a products table that contains normal products and configurable product It
HEllo, I have a hybrid iPhone application that has a UITabBarController and 5 Tabs.
Hello I have a table that contains days of the week, a table with
Hello I have a table with articles and the articles have a column category.
Hello I have a table has some info like this id | message 1
Hello there I have a database that has 2 tables in it, one is
I have a HTML file that has code similar to the following. <table> <tr>
I have a table that has some content in it. Not all rows has

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.