2017-07-04 85 views
0

我不得不项目实体框架的核心 - 身份 - 多项目

ASP.NET核心的Web应用程序(.NET核心)

ExternalEntityFramework

和类库(.NET核心)

ExternalEntityFramework.Data

enter image description here

这是在this link之后创建的,但在.NETCore上。我现在很困惑,因为我无法在ExternalEntityFramework.Data上创建迁移,因为没有启动类,而且我不知道如何在类库项目中。

有人可以给我一点指导,为实体框架核心数据访问创建单独的项目?

回答

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; 
    } 
} 

通过这个类,您可以在库项目中添加servserv。然后,您应该在主项目上的startup.cs中调用此方法,此前添加对ExternalEntityFramework.Data的引用。

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

你可以通过的ConnectionStringExternalEntityFramework字符串作为参数。

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

我在尝试这个我自己,所以也许这不是这样做的最佳方式。但它的作品。