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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:34:39+00:00 2026-05-26T15:34:39+00:00

I am using Entity framework 4.1 I have regular object, and I set his

  • 0

I am using Entity framework 4.1

I have regular object, and I set his ID to be something like 123456789 (long value)

Then I call SaveChanges()

the problem is SaveChanges() is changing my ID both in the memory and inside the database
it assign the ID to be 20

and if I will repeat this it will assign the id to be 21 and so on..

What can cause this behavior? and what should I do to solve it?

ID declaration:
public long ID { get; set; }

It have been worked before, it may worked before when the ID was declared as int (change it back to check is too large modification..)

Thanks

  • 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-26T15:34:40+00:00Added an answer on May 26, 2026 at 3:34 pm

    the problem is SaveChanges() is changing my ID both in the memory and
    inside the database it assign the ID to be 20

    Most likely the ID column in the database is an Identity column, so the Id gets assigned by the database, not by you. If you really want to assign the Id value yourself, remove the Identity property of the column.

    Assuming you are not using code first and you are working with Sql Server open up the table in SQL Server Management Studio and go to the column properties for the ID column – select “(Is Identity) – No”.

    enter image description here

    Edit:

    For code first you can force a non-identity key using the attributes

      [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
    

    on the ID property. Is there a particular use case why you want to do this? Usually its easier letting the database handle uniqueness of the key.

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

Sidebar

Related Questions

I have EntityTypes generated from a database using Entity Framework 4. I would like
I'm using Entity Framework in my project, and I have the problem that, once
I am using Entity Framework with my website. To improve performance, I have started
I have a problem with the following Linq query using Entity Framework: from o
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have
Trying to map the following schema using the Entity Framework. A Customer can have
Can anyone help? I have been using the entity framework and its going well
So, I am using the Linq entity framework. I have 2 entities: Content and
I have an app using the ADO.NET entity framework (the VS2008 version, not the
Using ASP MVC and Entity Framework. In the view, you have a page declaration

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.