エンティティ フレームワークを使用して、クラス内のデータベース内のクラスをマップしますObjectContext
。
var typesToRegister = Assembly.GetExecutingAssembly().GetTypes()
.Where(type => !String.IsNullOrEmpty(type.Namespace))
.Where(type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration<>));
foreach (var type in typesToRegister)
{
dynamic configurationInstance = Activator.CreateInstance(type);
modelBuilder.Configurations.Add(configurationInstance);
}
//Replace with ....
//modelBuilder.Configurations.Add(new EntityMap());
上記のコードはすべてのクラスを取得しますtypeof(EntityTypeConfiguration<>)
。私の「EntityMap」クラスが私のオブジェクト コンテキストと同じクラス ライブラリにある場合は問題map classes
ありませんが、別のクラス ライブラリに書いた場合は機能しません。Map classes
で識別できませんObjectContext
。