Project DescriptionFluent 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.