相关疑难解决方法(0)

具有配置的类库中的实体框架7迁移支架

尝试将迁移添加到位于ASP.NET 5类库中的EF7模型.当运行dnx . ef migration add mymigration失败时会有不同的结果,具体取决于我运行它的项目.

如果我在主项目的文件夹中运行它,它找不到DbContext,这是有道理的,因为DbContext它在共享项目中,而ef命令可能不关心依赖项.

如果我在共享项目的文件夹中运行它,它就无法访问startup.cs中指定的连接字符串.我从这样的问题收集是它从共享的项目工作,如果你指定要在连接字符串OnConfiguring的方法DbContext,但我真的想保持这个代码从配置独立.

我在EF7存储库中遇到了一些问题日志,提到他们实现了用于指定项目和上下文的命令行选项,但没有示例,我无法通过查看提交历史记录中的源代码来弄清楚如何使用它.

ef-migrations entity-framework-core visual-studio-2015 dnx asp.net-core

11
推荐指数
1
解决办法
3990
查看次数

.NET核心实体框架 - 在类库中为Context添加迁移

我在向.NET Core类库中的Entity Framework数据库上下文添加初始迁移时遇到问题.

当我跑:

dotnet ef migrations add migrationName -c PlaceholderContext
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Could not invoke this command on the startup project 'Placeholder.Data'. This version of the Entity Framework Core .NET Command Line Tools does not support commands on class library projects in ASP.NET Core and .NET Core applications. See http://go.microsoft.com/fwlink/?LinkId=798221 for details and workarounds.
Run Code Online (Sandbox Code Playgroud)

所以我点击了链接,了解到无法将迁移添加到类库中.但是,您可以将类库项目转换为"app"项目,但通过这样做,我无法从业务层(类库)引用此"app"项目.

项目结构:

Placeholder.Web(WebAPI)=> Placeholder.Business(类库)=> Placeholder.Data(类库)

项目结构

Placeholder.Web => Startup.cs

    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddApplicationInsightsTelemetry(Configuration);

        services.AddMvc();

        //HERE WE …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework .net-core asp.net-core

10
推荐指数
1
解决办法
5769
查看次数