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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:19:35+00:00 2026-06-15T16:19:35+00:00

Let’s say I got the following Entity Framework Ruimte model: public class Ruimte {

  • 0

Let’s say I got the following Entity Framework “Ruimte” model:

public class Ruimte
{
    #region Constructor

    public Ruimte()
    {
        Kenmerken = new List<Kenmerk>();
    }

    #endregion

    #region Properties

    [Key]
    public int Id
    {
        get;
        set;
    }

    [Required]
    public string Naam
    {
        get;
        set;
    }


    public List<Kenmerk> Kenmerken
    {
        get;
        set;
    }

    #endregion
}

And the “Kenmerk” model looks the following:

public class Kenmerk
{
    #region Properties

    [Key]
    public int Id { get; set; }

    public KenmerkOptie KenmerkOptie
    {
        get;
        set;
    }

    [Required]
    public int KenmerkOptieId
    {
        get;
        set;
    }

    [Required]
    public string Waarde
    {
        get;
        set;
    }

    [Required]
    public int RuimteId
    {
        get;
        set;
    }

    #endregion
}

And in my Ruimte/Create view there are 2 fields for adding a “Kenmerk”. Now a “Kenmerk” can’t go into the database without having a KenmerkOptieId or Waarde. So the view will reject the submit everytime I try to post the form because of the validation. Though I want a “Ruimte” to have or not to have a “Kenmerk”.

So the solution I went for was having a “RuimteCreateViewModel” with the properties “Name” which was required and a list of the another copmlex class called “KenmerkCreateViewModel”. Now in this last viewmodel the KenmerkOptieId and the Waarde are not required so I finally CAN submit the form.

Though I don’t think this is the best solution of “skipping” the required field validators. So what is your “best practice” when the database validation is different from the view 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-15T16:19:36+00:00Added an answer on June 15, 2026 at 4:19 pm

    I think xVal – a validation framework for ASP.NET MVC, see http://blog.stevensanderson.com/2009/01/10/xval-a-validation-framework-for-aspnet-mvc/ is very useful for the entity framework model that you are trying to develop. Especially the use of enforcing server-side validation, it allows you to choose to validate simple property formatting rules during property setters. See http://blog.stevensanderson.com/2008/09/08/thoughts-on-validation-in-aspnet-mvc-applications/ for an explanation.

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

Sidebar

Related Questions

Let's say I have the following classes : public class MyProductCode { private String
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say that I have classes like this: public class Parent { public int
Let me explain best with an example. Say you have node class that can
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say I have one class User, and it has a property of type
Let's say I have two Entity classes: SocialApp and SocialAppType In SocialApp I have
Let's say you have a class library project that has any number of supplemental

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.