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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:03:53+00:00 2026-05-16T11:03:53+00:00

I have a table with a nullable integer field that is a foreign key.

  • 0

I have a table with a nullable integer field that is a foreign key. When I try to set the entity model’s Nullable property to True I get an error that states that fields of type Int32 can not be null. So if Entity Framework doesn’t support nullable integers, how can I insert rows into the table with a null value? If no value is specified for the nullable property Entity Framework inserts a value of 0 which throws an error because of the foreign key constraint.

SQL Server is fine with a nullable foreign key so I’d like to keep the check constraint in place. What are my options here?

Thanks in advance!

  • 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-16T11:03:53+00:00Added an answer on May 16, 2026 at 11:03 am

    EF does support a nullable int. But int and int? are two different types. Generate a new model against a nullable int column and you’ll see.

    The reason that updating your model didn’t change the multiplicity of the association is that the EF tries to preserve your CSDL customizations when you update. It will regenerate SSDL mostly from scratch, and add to the CSDL any new objects/relationships, but it doesn’t overwrite changes you might have made.

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

Sidebar

Related Questions

I have a table that has several nullable integer columns. This is undesirable for
I have a table with a nullable datetime field. I'll execute queries like this:
I have a table that has a primary key that's an INT... I have
I have a table with a nullable FK field. I made it nullablle to
I have two simple entities: My\Entity\Coupon: type: entity table: coupon id: id: type: integer
I have a table with a nullable field of type text. When I run
I'm working with .NET strongly-typed datasets and have a table with a nullable int
I have table with around 70 000 rows. There is 6000 rows that i
I have table with 300 000 records (MyISAM). I get record from this table
I have table of data that is sorted as follows: Item | Sample |

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.