3 つのエンティティ クラスと DbContext を備えた C# クラス ライブラリを作成し、データベースのコード ファースト生成を行いました。バージョン 1 ですべてがうまくいきました。別のテスト ライブラリを作成しましたが、DbContext クラスを含むクラス ライブラリは期待どおりに動作しています。
ここで、フィールドの 1 つを必須にしたいと考え、コード ファーストの規則に従って、エンティティ クラスのプロパティに [Required] 属性を追加しました。次のステップは、移行を有効にすることでした。
パッケージ マネージャー コンソールに移動し、「enable-migrations」と入力して ... bang ... 「指定されたメタデータ リソースを読み込めません」と入力しました。
参考までに、私の DbContext クラスには以下が含まれています。
public OrganisationsContext()
: base("Leegz_Entities_Organisations")
{
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}
public DbSet<Organisation> Organisations { get; set; }
public DbSet<Member> Members { get; set; }
public DbSet<LeegzUser> LeegzUsers { get; set; }
そして私のapp.configには以下が含まれます:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="Leegz_Entities_Organisations" connectionString="data source=NEIL-INSPIRON\NEILDEV;initial catalog=TheLeegz;integrated security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="Leegz.Entities.Organisations.DbSecuritySchema" value="Leegz.Entities.Organisations"/>
</appSettings>
</configuration>
この件に関する多くのスレッドを見てきましたが、それらはすべて EDMX モデル ファイルの参照要素のエラーについて話しているようです。ただし、コード ファーストを使用したため、モデルがありません (ここで手順が不足している可能性があります)。そのため、接続文字列の EDMX 情報に関連して見たアドバイスは、私に適用する。
何かアイデアはありますか?