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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:57:43+00:00 2026-06-12T15:57:43+00:00

A typical EF+MVC system will have two or three levels of validation: For ViewModel:

  • 0

A typical EF+MVC system will have two or three levels of validation:

  1. For ViewModel: input / physical validation (DataAnnotations, FluentValidation), in other words, length, null, range, regex, etc.
  2. For Model: input / physical validation (repeat of 1 in case MVC is not used and data comes from another system, WCF, forms, etc.)
  3. For Model: logical / “business rules” validation

I can’t find best practices for validation of 2+3 for the actual Model / entities / domain / “business rules”. We either:

  • put simple validation rules in an entity’s property setter (but this is really messy)
  • hook into EF’s SaveChanges(), and if an entity is in the Added or Modified state then trigger validation (which validates the entire entity at once)

This is hard to maintain. A lot of thought went into ViewModel validation, but for Model validation it is domain-specific and so it is for you to determine a creative solution, and mine is not that great.

  • Are there better ways to do this, or helpful tools (like maybe DataAnnotations or FluentValidation but for domain entities)?
  • Where is the best place to do model validation or to trigger the model’s validation?
  • 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-12T15:57:44+00:00Added an answer on June 12, 2026 at 3:57 pm

    A typical MVC+EF system will have 3 layers, but they aren’t what you’re talking about.

    1. Presentation Layer (input/output)
    2. Business Layer (Logical layer)
    3. Data Layer (model represents low-level data)

    MVC provides validation for layer 1. EF provides validation for layer 3. There is no validation functionality provided by either MVC or EF for layer 2. If you want validation there, you have to do it yourself, or use a third party business object framework.

    Validation in layers 1 and 3 are separate, even though in many cases they may have similar validation. The reason is that validation is accomplished in different ways, and with different requirements.

    For example, you may have a field in your database that is nullable for data modeling or business logic reasons (let’s say some data is pre-loaded and the user is required to update the field as part of the business process). The data layer says it’s nullable, but you want your UI to make it required.

    EDIT:

    Simply put, the Data model should not be enforcing business rules. Therefore, you should not need any validation in the data model, other than to validate against the physical data model (ie, if the field is nullable, the data type in the model should nullable, otherwise not). In most cases, you physically cannot insert invalid (from the data models perspective) data because the code model will not allow it. The only exception to this is string variables, which can obviously overflow the size constraints of the physical model, but if that happens then an exception gets thrown anyways.

    Your middle tier, the business layer, should be where you need to validate business rules (for example, that a customer purchase order must start with a letter). Neither MVC or Entity Framework, or WCF or whatever provide any way to do this validation.

    There is a bit of a disconnect here, because the business rules should (in theory) drive the presentation layer validation. But, MVC has no built-in functionality to do that, though. So you end up duplicating your business rules in the UI.

    There is at least one third party business object framework that tries to deal with this. CSLA. They provide a custom MVC model binder that ties in the business objects with the UI to do validation, but this is just using the built-in extendibility of MVC to do this.

    So, if you don’t want to use a dedicated business object framework, you are stuck either duplicating validation between UI and Business layer, or trying to figure out your own way to make your own business layer control UI validation.

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

Sidebar

Related Questions

In a typical MVC application we have validation that occurs in many different places.
The typical Python threadpool will have a structure like this one: def run(self): while
I have an ASP.NET MVC View with the typical TitleContent and MainContent, with a
I'm working on a typical CRUD application in ASP.NET MVC where there will be
In your typical MVC application, you have many layers. Database layer Model layer (possibly
I have an Asp.Net MVC project with the typical forms authentication that redirects the
I have a small Spring web application, with the typical MVC Service DAO JPA/Hibernate
I have a typical Spring MVC + GWT architecture with Apache Shiro as a
I have a PHP MVC framework with multiple 'applications' under this system the organization
In my MVC 2 application I have a typical method that calls a web

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.