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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:48:25+00:00 2026-05-21T13:48:25+00:00

Is there a best practice or widely accepted way of structuring and validating data

  • 0

Is there a best practice or widely accepted way of structuring and validating data using MVVM in conjunction with RIA services in Silverlight?

Here’s the crux of my problem. Let’s say I have an EmployeeView, EmployeeViewModel and some Employee entity. In regular RIA applications I will expose that Employee entity on the view and I get validation “for free”, because Entities implement INotifyDataErrorInfo and IDataErrorInfo (correct?).

Now if I want to expose some Employee properties through a ViewModel instead of directly through an Entity then it becomes more complicated. I could expose the bits that I need directly and hook them into the entity on the backend, like this:

    private Employee _employee;

    public EmployeeViewModel()
    {
        _employee = new Employee();
    }

    public string Name
    {
        get { return _employee.Name; }
        set
        {
            _employee.Name = value;
            // fire property change, etc.
        }
    }

… but I lose the tasty “free” validation of entities. Otherwise, I could expose the entity directly in the view model, like so

    private Employee _employee;
    public Employee Employee
    {
        get { return _employee; }
    }

    public EmployeeViewModel()
    {
        _employee = new Employee();
    }

In this case, the view will bind directly to the Employee entity and find its properties in there, like so:

<StackPanel DataContext="{Binding Employee}">
    <TextBox Text="{Binding Name}" />
</StackPanel>

Using this method we get “free” validation, but it’s not exactly a clean implementation of MVVM.

A third option would be to implement INotifyDataErrorInfo and IDataErrorInfo myself in the VMs, but this seems like an awful lot of plumbing code, considering how easy it would be for me to use the above solution and have something slightly less “clean” but a heck of a lot easier at the end of the day.

So I guess my question is, which of these approaches are appropriate in which situation? Is there a better approach I am missing?

In case it’s relevant I’m looking at the Caliburn.Micro MVVM framework, but I would be keen to see answers that apply generically.

  • 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-21T13:48:25+00:00Added an answer on May 21, 2026 at 1:48 pm

    I am using RIA with Caliburn.Micro and am pretty happy with my solution for client side validation.

    What I have done is put a ValidationBaseViewModel between Screen (provided by Caliburn.Micro) and my actual application VMs (EmployeeViewModel in your case). ValidationBaseViewModel implements INotifyDataErrorInfo so that plumbing code your talking about is only written once. I then add/remove/notify of errors via ValidationBaseViewModel from an override of the (Caliburn.Micro) PropertyChangedBase.NotifyOfPropertyChange with the following code:

    public override void NotifyOfPropertyChange(string property)
    {
        if (_editing == null)
            return;
    
        if (HasErrors)
            RemoveErrorFromPropertyAndNotifyErrorChanges(property, 100);
    
        if (_editing.HasValidationErrors)
        {
            foreach (var validationError in
                           _editing.ValidationErrors
                                   .Where(error => error.MemberNames.Contains(property)))
            {
                AddErrorToPropertyAndNotifyErrorChanges(property, new ValidationErrorInfo() { ErrorCode = 100, ErrorMessage = validationError.ErrorMessage });
            }
        }
    
        base.NotifyOfPropertyChange(property);
    }
    

    This is actually in another VM (between ValidationBaseViewModel and EmployeeViewModel) with the following definition:

    public abstract class BaseEditViewModel<TEdit> :
                                    ValidationBaseViewModel where TEdit : Entity
    

    where Entity is RIAs System.ServiceModel.DomainServices.Client.Entity and the _editing class member is an instance of this type TEdit which is being edited by the current VM.

    In combination with Caliburn coroutines this allows me to do some cool stuff like the following:

    [Rescue]
    public IEnumerable<IResult> Save()
    {
        if (HasErrors)
        {
            yield return new GiveFocusByName(PropertyInError);
            yield break;
        }
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a best practice in getting data from multiple database tables using Zend?
Is there a best-practice or common way in JavaScript to have class members as
Is there any best practice data model for authentication/authorization scheme?
Is there a performance gain or best practice when it comes to using unique,
Is there a way in Cocoa that is currently considered best practice for creating
Is there a best practice when it comes to setting client side onclick events
Is there a best practice for avoiding a browser freeze when loading an applet?
It may not be best practice but are there ways of removing unsused classes
Are there any guidelines/best practices for deciding what type of data should be stored
What are the best practices for using autoconf in conjunction with shared_ptr and other

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.