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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:14:40+00:00 2026-05-24T16:14:40+00:00

I am using an Entity Framework 4 connection to connect to a SQL 2008

  • 0

I am using an Entity Framework 4 connection to connect to a SQL 2008 server to do database handling for my application.

I am using C# in Visual Studio 2010 and my question is regarding Primary Key fields that are incremented by the SQL itself, is it possible at all for me to be able to find the ID that will be used next by the database.

The reason why I cannot just find the last item and +1 is because if my table contains items 1,2,3,4 and 5, removing item 5 then adding another will make the next item become item 6, rather than 5 again (As I use the Identity Specification in SQL, but this must be used).

I cannot find any method such as Item.ID.GetNextIdentity() or something like that and have looked through as many similar questions like this but to no avail.

Any help would be appreciated

  • 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-24T16:14:41+00:00Added an answer on May 24, 2026 at 4:14 pm

    There is no reliable way to use auto incremented ID and show it in a form before you do the save. That is wrong architecture. If you want to have ID shown before saving the form you must either:

    • Not use auto incremented column as ID and handle uniqueness yourselves
    • Save the form immediately when user starts creating it in some initial empty state and the final form confirmation will do only update

    Why you cannot ask for next ID? Because if you do it in any way nobody says that received ID will be really used for your form. If another process / thread / application inserts form between your ID retrieval and your form persistence, the Id you shown will be assigned to that inserted form.

    Also if you are using auto incremented primary keys in the database you cannot assign the key value in your application – the value will not be used and database can override it with its own.

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

Sidebar

Related Questions

I'm trying to setup the Entity Framework with SQL Server 2008. I'm using Guids
I try to use SQL Server Compact Edition with Entity Framework in Visual Studio
I develop desktop-based WPF-application, that uses SQL Server 2008 R2 Database and ADO.NET Entity
I am using C#, Visual Studio 2010 and Entity Framework 4. I have an
How can I force my ASP.Net application to connect to a SQL Server using
I'm using entity framework to connect the database. I've a table(Let's call it File)
I'm trying to connect to an SQL Server 2008 database in a shared hosting
I switched my DAL from using LINQ over to Entity Framework. Because my application
I am using attempting to create a connection to an Oracle database via entity
Recently our WPF/Entity Framework 4.0 application has become unstable after we began using backgroundworkers

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.