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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:13:07+00:00 2026-06-12T15:13:07+00:00

I have an ID that is set to auto increment (int obviously). var dc

  • 0

I have an ID that is set to auto increment (int obviously).

var dc = new DataContext([STRING]);

var usersTable = dc.GetTable<Audit_User>();

var user = usersTable.FirstOrDefault(o => o.Username.Equals("NAME"));

if (user == null)
{
   user = new Audit_User()
   {
      Username = "NAME"
   };

   usersTable.InsertOnSubmit(user);
}

//HERE - I need access to the user Id

dc.SubmitChanges();

For more context, please see the tags.

  • 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-12T15:13:08+00:00Added an answer on June 12, 2026 at 3:13 pm

    //HERE – I need access to the user Id

    Actually you do not. If you consistently use linq-2-sql you can assign the user entity instead of setting the user.id to populate a relation (most probable cause why you need the ID).

    So instead of doing

    somerelated_table.fk_user_id = user.id
    

    you do

    somerelated_table.user = user
    

    Linq-2-sql will handle the proper assignment of the user.id when you call SubmitChanges. Plus as a bonus it will all be done in a single transaction. That is the beauty of linq-2-sql.

    If you need the Id for some manipulation without using linq-2-sql, you can anyhow do it after the submitchanges and it will not matter anyway

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

Sidebar

Related Questions

I have an database table set up as shown below: copy_blocks id (auto-increment int)
I have a div that's set to overflow: auto; . This contents of this
I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated
I have a UILocalNotification that is set to start at 2012-06-18 10:00 with a
I have a ListView that is set up with a MinHeight and a MaxHeight.
I have a file that I set using PowerShell that contains the version number
I have a potential client that set up their website and membership system in
I have a function that I set custom key and value to it and
Problem: I have a value that is set in $record, for instance 1.69. Then
Currently I have a site that is set up using a masterpage and a

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.