T のすべての文字列プロパティを列挙し、IsUnicode(false) を設定できるようにする EntityTypeConfiguration<T> の汎用拡張メソッドを作成しようとしています。ここに私がこれまでに持っているものがありますが、StringPropertyConfiguration を取得しようとして行き詰まっています。このクラスのコンストラクターは内部にあり、そのインスタンスをどこで取得するかわかりません。
public static void SetStringsToBeNonUnicode<T>(this EntityTypeConfiguration<T> config) where T : class
{
PropertyInfo[] properties = typeof (T).GetProperties();
foreach (PropertyInfo p in properties)
{
var parameter = Expression.Parameter(typeof(T));
var property = Expression.Property(parameter, p);
var funcType = typeof(Func<,>).MakeGenericType(typeof(T), p.PropertyType);
var lambda = Expression.Lambda(funcType, property, parameter);
//This is the line where I need help
StringPropertyConfiguration stringConfig =
new System.Data.Entity.ModelConfiguration.Configuration.StringPropertyConfiguration(config.Property<System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.StringPropertyConfiguration>((LambdaExpression) property));
stringConfig.IsUnicode(false);
}
}