FluentMetadata, a Fluent API for defining metadata for WCF RIA Services entities

With permission of Nikhil Kothari, I've added the source code of Nikhil's Fluent API for defining WCF Ria Services Metadata to RIA Services Contrib. I've made a couple of changes. Most noticeable is the ability to attach a MetadataClass to your domain service using the FluentMetadata attribute. This class mimics the OnModelCreating method in EntityFramework DbContext and allows you to instantiate your Metadata classes. The original version is available here.

The main advantage of this package is that it allows you to separate your datamodel and metadata in separate projects/assemblies. This is not possible with the standard RIA services approach of buddy classes. These have to be defined in the same project as your datamodel. The drawbacks of this are a pollution of your datamodel and (most importantly) that your datamodel project becomes dependent on RIA services-specific assemblies. With the FluentMetadata package you can define metadata in any assembly you like.

Download: the package is available as a Nuget package.

Changes in version 0.2.69239.0
metadataContainer.Entity<Bar>()
    .Projection(x => x.FooSet)
        .Association()
            .WithName("MyAssociation")
            .WithThisKey(x => x.Id2, x=>x.Id)
            .WithOtherKey(x => x.Id2, x=>x.Id);

Using FluentMetadata
public class FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    public void OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Entity<Foo>().Projection(x => x.SomeProperty).Exclude();
    }
}
public class FooMetadata : MetadataClass<Foo>
{
    public FooMetadata()
    {
        this.Projection(x => x.ExcludedString).Exclude();
        this.Validation(x => x.RequiredString).Required();
        this.Validation(x => x.RegularExpressionString).RegularExpression("[a-z]");
    }
}
public class FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    public void OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Add(new FooMetadata());
    }
}

[EnableClientAccess()]
[FluentMetadata(typeof(FluentMetadataConfiguration))]
public class FluentMetadataTestDomainService : DomainService
{
}