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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:33:42+00:00 2026-06-04T08:33:42+00:00

Using the data annotation Required like so: [Required] public int somefield {get; set;} Will

  • 0

Using the data annotation Required like so:

[Required]
public int somefield {get; set;}

Will set somefield to Not Null in database, How can I set somefield
to allow NULLs?, I tried setting it through SQL Server Management Studio but Entity Framework set it back to Not Null.

  • 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-04T08:33:43+00:00Added an answer on June 4, 2026 at 8:33 am

    Just omit the [Required] attribute from the string somefield property. This will make it create a NULLable column in the db.

    To make int types allow NULLs in the database, they must be declared as nullable ints in the model:

    // an int can never be null, so it will be created as NOT NULL in db
    public int someintfield { get; set; }
    
    // to have a nullable int, you need to declare it as an int?
    // or as a System.Nullable<int>
    public int? somenullableintfield { get; set; }
    public System.Nullable<int> someothernullableintfield { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what can a problem that data annotation attributes are not rendered? web.config <appSettings> <add
How can I write the validation using data annotation in writing telephone number such
I'm using Data::Dumper to print a perl hash with configuration, which will be evaluated
I'm using the Data Annotation validation extensively in ASP.NET MVC 2. This new feature
I am trying to get client validation working in MVC3 using data annotations. I
With Data Annotations it's now easy to localize error messages using Resource.resx files like
My problem: I can't get Data Annotations Client Validation to work with a List
I like the idea of using the data annotations to specify validation of fields
I'm using linq to SQL and MVC2 with data annotations and I'm having some
I am using data-attributes in my portal page to describe favorite links. This is

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.