Fluent Metadata Custom Validation

Nov 8, 2012 at 10:46 AM

I'm trying to use Custom Validation with Fluent Metadata but it doesn't have any documentation or sample usage.

Can someone provide a sample for this?




Nov 9, 2012 at 10:27 PM


Suppose you have a class Person with a property FirstName, and a class TestPersonData with a method CheckFirstname like this:


public class PersonDataValidator
            public static ValidationResult ValidateFirstName(string firstName)
                    return new ValidationResult(
                        "Invalid first name.");
                return ValidationResult.Success;



Now you can use the Fluent API to register this validation method for the property FirstName on the entity Person:

            metadataContainer.Entity<Person>().Validation(x => x.FirstName).Custom<PersonValidator>("ValidateFirstName");

I hope this helps you

Kind regards,


Nov 9, 2012 at 10:52 PM

Hi Merijn.

I'll try it.