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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:59:52+00:00 2026-05-20T16:59:52+00:00

I’m using Entity Framework 4 and a Dynamic Data site to expose a bare-bones

  • 0

I’m using Entity Framework 4 and a Dynamic Data site to expose a bare-bones admin interface to a few users. Working pretty well in general, but I have run into this one problem on a couple of fields on my model.

Several tables have some audit-related fields – CreatedBy, CreatedDate, ModifiedBy, and ModifiedDate. These fields are required in the database and the associated models are marking the properties as non-nullable (all as it should be). However I am handing setting the values for these fields in code – the field templates for the field types mark these specific fields as disabled on the page, and in the SavingChanges event I set these fields to the appropriate values. All works great when I’m updating an existing item.

The problem comes in when I try to create a new item. I want these fields to remain empty on the page and be auto-populated by my code when submitted, but the Field Templates set up RequiredFieldValidators for these fields and won’t let me submit them without a value. Normally this would be great, except that I want to prevent EF from validating these fields at the point of page submission.

I realize that I could mark the fields as nullable in the database and that would resolve the issue – it would probably even be just fine from the data standpoint, but I’m not comfortable with doing so – for one thing it’s not unlikely that some of the models these fields appear on will be bulk loaded, possibly by someone else, at a later date. I would rather still have the database enforce the non-nullability of these fields. In the field templates I’ve tried moving the built-in SetUpValidator() call for the RequiredFieldValidator not to run when these specific fields are being loaded, and I’ve also tried disabling the RequiredFieldValidators and forcing their IsValid property to true. None of these actions allows me to submit the page.

Is there a way to tell EF/Dynamic Data to skip the validation for some fields?

EDIT

As noted below, I also tried marking them nullable in the model and not in the database, which caused an error: Problem in mapping fragments...Non-nullable column...in table...is mapped to a nullable entity property.

EDIT #2

I have found a solution that works, but requires modifying the auto-generated designer file for the entity set, which is fragile at best. I would love to know a “righter” way to do it, but if nothing becomes apparent in the next couple of days I’ll post my own answer.

  • 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-20T16:59:52+00:00Added an answer on May 20, 2026 at 4:59 pm

    So here are the edits I found I had to make. When allowing the tool to create the entities in the edmx Designer.cs file I get properties like these:

    for a datetime on the server side

     [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
     [DataMemberAttribute()]
     public global::System.DateTime CreatedDate
     {
        get
        {
           return _CreatedDate;
        }
        set
        {
           OnCreatedDateChanging(value);
           ReportPropertyChanging("CreatedDate");
           _CreatedDate = StructuralObject.SetValidValue(value);
           ReportPropertyChanged("CreatedDate");
           OnCreatedDateChanged();
        }
     }
    

    for a varchar

     [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
     [DataMemberAttribute()]
     public global::System.String CreatedBy
     {
        get
        {
           return _CreatedBy;
        }
        set
        {
           OnCreatedByChanging(value);
           ReportPropertyChanging("CreatedBy");
           _CreatedBy = StructuralObject.SetValidValue(value, false);
           ReportPropertyChanged("CreatedBy");
           OnCreatedByChanged();
        }
     }
    

    To make it work without validation for a DateTime property setting the IsNullable parameter of the EdmScalarPropertyAttribute to true is sufficient to avoid the issue. For the String property you also have to change the 2nd parameter of the SetValidValue method call to “true.”

    All of this said, the only reason that I’m leaving this as it is is because I don’t expect to have to regenerated the entities more than once or twice before we move to a different platform for this site. And in this case, merging the version in I have checked in to git with the version generated by the tool allows me to avoid most of the headaches,

    • 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'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.