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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:11:52+00:00 2026-05-16T22:11:52+00:00

I’ve just ran into an unexpected behaviour for Entity framework entities in use with

  • 0

I’ve just ran into an unexpected behaviour for Entity framework entities in use with ASP.NET MVC application with SQL Server as datastore. For a column marked as not null allowed I did not set up data annotation Required attribute inside the entities’ metadata partial class (I was under impression that I had to for all properties that I wish to make mandatory) but after the POST from my view the controller action returned to the same view as a result of this check

        // check for errors
        if (!ViewData.ModelState.IsValid)
            return View(invoice);

with a description that a property should not be null. I deliberately posted the textbox for the property empty and I have no custom (manual) Data Annotation attributes in place for this property.

This is the EF wizard generated code for this property

    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.DateTime PayDate
    {
        get
        {
            return _PayDate;
        }
        set
        {
            OnPayDateChanging(value);
            ReportPropertyChanging("PayDate");
            _PayDate = StructuralObject.SetValidValue(value);
            ReportPropertyChanged("PayDate");
            OnPayDateChanged();
        }
    }
    private global::System.DateTime _PayDate;
    partial void OnPayDateChanging(global::System.DateTime value);
    partial void OnPayDateChanged();

Is it the IsNullable attribute’s fault for this kind of behaviour? Let me be clear that if it indeed is so, then this is quite nice, though I haven’t noticed it before and would like to verify if that’s the right behaviour or do I have something messed up there?

  • 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-16T22:11:53+00:00Added an answer on May 16, 2026 at 10:11 pm

    There are a couple of different things going on here. First, EF will generate the property as DateTime for NOT NULL date columns in the database and it will generate Nullable for NULL date columns in the database. That’s point one.

    Point two is that MVC 2 has some “default” behavior in the default model binder. That is, for all value types it will perform a validation (independent of data annotations) that the user typed in a value. If they didn’t it will show the validation that you are currently seeing.

    So that explains what you are seeing. However, there are a couple other points to keep in mind. First, it’s still a good practice to use the [Required] attribute because this allows you to customize the error message displayed to the user. Secondly, it’s generally considered best practices to use a view model for your views rather than your EF domain model directly in your views. So I’d recommend creating a view model (you can just use AutoMapper to map the properties if your view model matches your domain model), and then using the data annotations to provide more fine-grained control over the metadata – not just validation, but also [DisplayName], [UIHint], etc.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.