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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:43:39+00:00 2026-05-24T12:43:39+00:00

I am using Visual Studio 2010 SP1 with MVC3 Tools Update, and EF 4.1

  • 0

I am using Visual Studio 2010 SP1 with MVC3 Tools Update, and EF 4.1 Code First to scaffold my application’s database.

Database CRUD operations work fine when testing locally and on a local database. It is not until I migrate the database to web host’s SQL Server 2008 R2 and target that hosted database in my connection string that all INSERT operations fail.

Whenever I try to add a new record I get this error: [I]Cannot insert the value NULL into column ‘Id’, table ‘DB_23378_bloomlmsdata.dbo.Courses’; column does not allow nulls. INSERT fails. The statement has been terminated.[/I]

My data models all specify a Primary Identity Key like so:

[Key]
public int Id {get; set;}
...

And in the local database that gets scaffolded, I see a non-nullable Primary Identity Key in each table.

I read somewhere that Entity Framework, when performing an INSERT operation to the database it will first try to insert a record with a null value as the Primary Key. I do not know how to override this behaviour. Also, this does not seem to be a common problem and people usually only run in to this when they use something different than an IDENTITY key. For the record, I had the same problem with EF CodeFirst CTP5 before EF 4.1 was released.

I have been troubleshooting this for 4 weeks.. My web host is up to date with the technology I am using in my application and database. When I try to get help, they are telling me it is a coding issue but my code checks out. Any ideas would be greatly 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-24T12:43:40+00:00Added an answer on May 24, 2026 at 12:43 pm

    Check the IsIdentity property of the Id column, it should be set to yes. EF doesn’t pass a value for the identity column on an insert because it should be auto-generated by the database.

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

Sidebar

Related Questions

Using Visual Studio 2010 beta, when I run my application within the IDE for
Setup: I am using MVC 3, EF 4.1, Visual Studio 2010 SP1 with Power
Using Visual Studio 2010 SP1, SQL server 2008: Motherboard recently failed and I migrated
I have been using Visual Studio 2010 SP1 for C++ in the default setting
I am using Visual Studio, developing a native application, I have a programmatical breakpoint
I'm using Visual Studio 2008 and the built-in installation tools for a C# client
I was using the latest EF 4 bits in Visual Studio 2010 RC and
Using Visual Studio 2008 Team Edition, is it possible to assign a shortcut key
Using Visual Studio 2008 / C# / VS Unit Testing. I have a very
When using Visual Studio (though ideally this can apply to the generic case) and

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.