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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:21:42+00:00 2026-05-26T19:21:42+00:00

Is there any way to get dataanotations for my models directly from my database?

  • 0

Is there any way to get dataanotations for my models directly from my database?
I have a database with lot’s of data and tables, so i am generating my model with entity framework from database, so i get classes, but i want to know can entity framework or some other orm get properities and constrains directly from database and put them in classes as data anotation like [required] or [datatype(datatype.emailadress)]

  • 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-26T19:21:43+00:00Added an answer on May 26, 2026 at 7:21 pm

    Yes. You can inherit the ModelMetadataProvider class:

    public class LocalizedModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
    
        protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType,
                                                        Func<object> modelAccessor, Type modelType, string propertyName)
        {
            var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
            if (containerType == null || propertyName == null)
                return metadata;
    
            // Load all metadata from your database here.
    
            return metadata;
        }
    
    }
    

    I’m creating a project called Griffin.MvcContrib which is almost done and has a administration area where you can handle all localization (zero-code) for both models and validation messages.

    By using it you can just implement the following interface to get support for your database:

    // the actual code file has detailed explanations of each method.
    public interface ILocalizedStringProvider
    {
        string GetModelString(Type model, string propertyName);
        string GetModelString(Type model, string propertyName, string metadataName);
        string GetValidationString(Type attributeType);
        string GetEnumString(Type enumType, string name);
    
    }
    

    Update

    Where is not important. And you do not have to use DataAnnotation attributes on your models (the [Display] attribute). I just inherit the DataAnnotationsModelMetadataProvider to be able to use the attributes.

    1. Create the class anywhere.
    2. Read from the database
    3. Configure MVC to use it in global.asax

    Example:

     ModelMetadataProviders.Current = new YourModelMetadataProvider();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to get an ER model of a database from the
Is there any way to get raw data from framebuffer /dev/graphics/fb0 programmatically?
Is there any way to get session of salesrule using model? I have to
Is there any way to get a list of properties name from Properties and
Is there any way to get all keys from an STL hash_map? Or I
Is there any way to get info like progress from another process? What I'm
Is there any way to get the Form from its Processhandle ? Some thing
Is there any way to get input from a file one number at a
Is there any way to get the Derived Class Name from static Keyword ?
Is there any way to get the Oracle query from PreparedStatement .I know its

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.