Search
Project Description
Fluent Metadata allows you to use a fluent interface to add metadata to your entities. The library is written in C#.

Available documentation:

This project allows you to move to the fluent way of adding metadata to your entities. A short example is shown below.

Default way of adding metadata:
public class Product {
  public int Id {get; set;}
  public string Name {get; set;}
}

public class ProductMetadata {

  [Key]
  public int Id;

  [Required]
  [StringLength(50){ ErrorMessage = "The string should be shorter than 50 characters"}]
  public string Name;
}

Syntax used by this library to add metadata:
public class Product {
  public int Id {get; set;}
  public string Name {get; set;}
}

public class ProductMetadata : FluentMetadata<Product> {
  ForProperty(p => p.Id).AddValidation.IsKey();
  
  //Yes you can call ForProperty multiple times for the same property :)
  ForProperty(p => p.Name).AddValidation.IsRequired();
  ForProperty(p => p.Name).AddValidation.StringLength().Maximum(50).WithErrorMessage("The string should be shorter than 50 characters"); 
}

Moving to the fluent way of adding metadata allows you to refactor easier because references are automatically updated and you have IntelliSense support when mapping the metadata.
Last edited Oct 8 2009 at 11:40 PM by jvandertil, version 13
Updating...
© 2006-2012 Microsoft | Get Help | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2012.1.11.18365