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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:21:29+00:00 2026-05-29T15:21:29+00:00

In my application I used Entity Framework generated from a db with ado.net dbcontext

  • 0

In my application I used Entity Framework generated from a db with ado.net dbcontext generation as well.

The client side works well when there’s a not null fk but for the fields line a varchar/nvarchar not null the mvcvalidator just doesn’t seem to recognize that the field is should be “required”.

Any idea why this happens?

  • 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-29T15:21:30+00:00Added an answer on May 29, 2026 at 3:21 pm

    No the Mvc Validator isn’t going to read your database metadata and perform client validation.

    Typically you would create a ViewModel/DTO and place validations there. Like a product for example, see how the fields have Attributes, these are from the System.ComponentModel.DataAnnotations Namespace and are used to decorate your models with validation constraints.

     public class Product
     {
            public int Id { get; set; }
    
            [Required]
            [StringLength(10)]
            public string Name { get; set; }
    
            [Required]
            public string Description { get; set; }
    
            [DisplayName("Price")]
            [Required]
            [RegularExpression(@"^\$?\d+(\.(\d{2}))?$")]
            public decimal UnitPrice { get; set; }
        }
    

    See the full example here:
    http://www.asp.net/mvc/tutorials/older-versions/models-(data)/validation-with-the-data-annotation-validators-cs

    You use the model (like above) in your view, mvc will perform the validations, even client side, and then use the returned object instance to fill your entity model.

    If you do not want to create separate classes and insist on using Entities from EntityFramework you could create a buddy class.

    See this article:
    http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

    Scroll down to => But what if we are using a graphical tool for our ORM mappings?

    There is a Person, and it is linked up with the Validator class by tge MetadataTypeAttribute

    Something like:

    [MetadataType(typeof(PersonMetaData))]
    public partial class Person
    {
    }
    public class PersonMetaData
    {
        [Required(ErrorMessage = "Name is required.")]
        public object Name;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my asp.net mvc 3 application with entity framework and i used the
i separated my application into a DAL, BL, UI. I used entity framework code
I use Asp.net 4 in C# and Entity Framework 4. My web application is
I've been playing with ADO.NET Entity Framework lately, and I find that it suits
I've used WCF RIA services with Entity Framework to build a simple application which
I am using ADO.NET Mocking Context Generator plugin for my Entity Framework model. I
I'm incorporating Entity Framework and ASP.NET Dynamic Data into an existing application that is
I need to use an Entity framework with my application, and I have used
I'm writing a ASP.NET application used within our company. Now I want to send
Recently I've read article The Entity Framework In Layered Architecture and there is written

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.