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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:55:47+00:00 2026-06-12T12:55:47+00:00

In order to experience the new features of Entity Framework I created a new

  • 0

In order to experience the new features of Entity Framework I created a new MVC 4 internet application.
I connected it to an existing database and generated the Model classes with the dbContext generator.

By running the application I got some validation errors while editing a form. As example for a DateTime field the system was complaining if the date was inserted as “12/10/2012” instead of 2012-10-12 (as in the SQ Server notation).
I tried to find the validation code in the project, but I could not find it anywhere in the generated code.

One of my model classes is the following:

public partial class Artist
{
    public Artist()
    {
    }

    public int Id { get; set; }
    public string Name { get; set; }
    public Nullable<System.DateTime> DateOfBirth { get; set; }

    public virtual Countries Countries { get; set; }
}

How can I customize the validation errors if using the Database first approach?
If I decor the models with my validation attributes, then they would be erased once the model classes are generated again.

Moreover in a “real world” project where the use of an existing database is mandatory, what would be the best approach with the development of the model classes?
Extending the classes automatically generated by adding partial classes with the same name?

EDIT (Introduced part of the View):

@using (Html.BeginForm()) {
@Html.ValidationSummary(false)

<fieldset>
    <legend>Movie</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Name)
        @Html.ValidationMessageFor(model => model.Name)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.DateOfBirth)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.DateOfBirth)
        @Html.ValidationMessageFor(model => model.DateOfBirth)
    </div>

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
}
  • 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-12T12:55:48+00:00Added an answer on June 12, 2026 at 12:55 pm

    Well, you can always use a metadata class

    public partial class ArtistMetaData
    {
       [Required]
       [StringLength(20)]
       public string Name;//it can be a field instead of a property, must just have the same name and type than in your Model class
    }
    

    and a partial class

    [MetadataType(typeof(ArtistMetaData)]
    public partial class Artist {
    }
    

    Or (my preferred solution) you can use an external Validation library, like the excellent FluentValidation

    You have a “basic” validation by default (which can be removed in the global.asax), checking : that the non nullables values… are not null (like a default Required attribute), and that values are of the right type.

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

Sidebar

Related Questions

I'm trying to 'AJAX-ify' my site in order to improve the UI experience. In
Order by descending is not working on LINQ to Entity In the following Query
In order to migrate smoothly a Rails 3.0.10 application which need to grow up
I am maintaining a Grails application that I did not write(I have no experience
I have two years of experience on iPhone programming but totally new to OpenGL.
I recently started learning about ASP.Net MVC and its various features MVC_3_MUSIC_STORE + CODE
I'm brand new to RoR and have pretty much 0 experience with it. I
I have just started a new database project to price customer bid proposals: Some
When coding new javascript heavy websites, which order or web browser do you code
I am making a simple game in order to learn a new language. I

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.