2017-07-04 6 views
0

プロジェクトEntity Frameworkのコア - アイデンティティ - 私が持っている複数のプロジェクト

ASP.NETコアのWebアプリケーション(.NETコア)

ExternalEntityFramework

とクラスライブラリ(.NETコア)へ

ExternalEntityFramework.Data

enter image description here

これはthis linkしかし.NETCore上で、次の作成されました。何のスタートアップクラスが存在しないので、私はExternalEntityFramework.Dataに移行を作成することはできませんので、私は、今、非常に困惑している、と私はどのようにクラスライブラリプロジェクトではわかりません。

は、誰かが私にEntity Frameworkのコアデータアクセスのための別々のプロジェクトを作成するにはほとんどの指針を与えることができますか?

答えて

0

あなたはExternalEntityFramework.Dataに以下のクラスを持っている必要があります。このクラスでは

public static class IServiceCollectionExtension 
{ 
    public static IServiceCollection AddProjectServices(this IServiceCollection services) 
    { 
     services.AddDbContext<SomeContext>(options => options.UseSqlite(connectionString, b => b.MigrationsAssembly("ExternalEntityFramework"))); 

     return services; 
    } 
} 

あなたはあなたのライブラリプロジェクト内のserviciesを追加します。次に、あなたのメインプロジェクト、ExternalEntityFramework.Dataへの参照の前に追加でstartup.csからこのメソッドを呼び出す必要があります。

public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddMvc(); 
    services.AddProjectServices(); 
} 

あなたは、パラメータとしてのConnectionStringExternalEntityFramework文字列を渡すことができます。

public static IServiceCollection AddProjectServices(this IServiceCollection services, string connectionString, string mainProject) 

私はこれを自分自身で試しているので、これを行う最適な方法ではないかもしれません。しかし、それは動作します。

関連する問題