I'm using Entity Framework Code First with map classes inheriting from EntityTypeConfiguration. I do this to encapsulate my use of the Code First fluent API for configuring entities.
I would like to be able to examine the configuration settings made in these classes, so that I can apply some of them in my integration testing. I'm using AutoFixture to create entities quickly, and ultimately I want to figure out a way to make some customizations that consume the configurations inside of my EntityTypeConfiguration classes.
But first, I need to figure out how to pull them out...
Here's a use case example:
public class Widget { public string Name { get; set; } }
public class WidgetMap : EntityTypeConfiguration<Widget> {
this.Property(w => w.Name).HasMaxLength(10);
}
How do I do something like this pseudo-code:
public Widget GetWidgetHonoringStringLengthConstraints(WidgetMap map) {
var w = new Widget();
int maxLength = map.GetProperty(p => p.Name).GetMaxLength(); //MAGIC
string name = new Guid().SubString(0, maxLength);
w.Name = name;
return w;
}