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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:47:36+00:00 2026-06-10T10:47:36+00:00

Quick question on best practices. I have one project MVC3 + razor that on

  • 0

Quick question on best practices.

I have one project MVC3 + razor that on my class, on each of my properties, I have some validations like these:

    [StringLength(20)]
    [RegularExpression(@"^[1-9][0-9]*$",ErrorMessage="Only Numbers Allowed") ]
    [Required(AllowEmptyStrings = false, ErrorMessage = "Please Inform The Code")]
    [Display(Name = "Code")]
    public string gCode { get; set; }

This is on my, let’s say, Customer class on my model. Validation works perfectly on the UI.

On a second project, when using Entity Framework – database first, I have my edmx file with my entities and I query the database using ObjectContext, which means the Customer class is built by EF.

Where am I supposed to add these validations now?

  • 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-10T10:47:38+00:00Added an answer on June 10, 2026 at 10:47 am

    Model first has this problem – but it can be solved using MetaData. Say you have a generated entity called Field and the Value field you want to decorate with a [Required] attribute, just do the following:

    namespace Model.Entities {
    
        [MetadataType(typeof(FieldMetadata))]
        public partial class Field : EntityBase {
    
        }
    
        class FieldMetadata {
            [Required]
            public object Value;
        }
    }
    

    Here you are adding metadata to the Value member of an existing class’s members that you cannot modify.

    EDIT: If it doesn’t work, make a call to the TypeDescriptor as well.

    TypeDescriptor.AddProvider(new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Field), typeof(FieldMetadata)), typeof(Field));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A quick question on best practice for handling images in a PHP/MySQL CMS. Each
Just a quick question about best practice in MVC development. Let's say that I've
Have a quick question about what would be the best way to implement iterators
I just have a quick best practice question regarding custom cells in a UITableView.
Quick question on best practice. I have an AJAX application where there are 4
I have a quick question on best practice and if getters and setters are
Quick question: I have a saga that can have a scenario where it needs
I have a quick question - is there a best practice in SQL Table
A quick question about best practice with PHP classes. I have seen people use
Just a quick question: What are people's practices when you have to define the

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.