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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:34:00+00:00 2026-06-16T11:34:00+00:00

Preface Feb 2015 If you are still using Entity Framework EDMX, please do yourself

  • 0

Preface Feb 2015 If you are still using Entity Framework EDMX, please do yourself a favor and checkout using Entity Framework Code First instead. The difference is that your tables are created from your model classes, rather than in EDMX where your model classes are created with your tables. It’s an all around easier solution, and the problem in this question doesn’t even exist!

Getting Started with Entity Framework 6 Code First using MVC 5

I have an existing SQL database, and I am using ADO.NET Enity Data Model for the model. I am trying to build some CRUD features into my MVC application.

In all the tutorials I have found on the subject, they build the model from scratch and add the attributes to the model class. For example:

    [Required]
    [StringLength(10)]
    public string Name { get; set; }

However, the model classes are auto-generated, so I think changing them is a bad idea (and will get written over anyway if the the database model is refreshed).

How would I add validation attributes?

  • 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-16T11:34:01+00:00Added an answer on June 16, 2026 at 11:34 am

    You can create a partial class, separate from the EF generated class, to store the metadata in.

    //Contact.cs - The original auto-generated file 
    [System.ComponentModel.DataAnnotations.MetadataType(typeof(ContactMetadata))]
    public partial class Contact
    {
        public int ContactID { get; set; }
        public string ContactName { get; set; }
        public string ContactCell { get; set; }
    }
    
    //ContactMetadata.cs - New, seperate class
    
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    internal sealed class ContactMetadata
    {
        [Required(ErrorMessage = "Name is required.")]
        [StringLength(5)]  
        public string ContactName;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preface: First time really using JavaScript + jQuery, so my problem likely stems from
Preface Please note, I'm not looking for a code solution, but rather insight into
Preface: I'm know that in most cases using a volatile field won't yield any
Preface I've rarely ever been a JS developer and this is my first attempt
Preface: This is not much about how to structure code within files. I have
Preface: This is the first real swing program I have done. I have a
Preface: I am an inexperienced java programmer handed one of his first assignments. If
A preface: I'm new to javascript and trying to create a web visualization using
Please let me preface this question with an apology. I am very new to
Preface I know the right code for these examples. What I want to know

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.