Entity framework 实体框架代码优先-更新数据库在项目中找不到.mdf

Entity framework 实体框架代码优先-更新数据库在项目中找不到.mdf,entity-framework,ef-code-first,package-managers,Entity Framework,Ef Code First,Package Managers,我正在首先创建一个带有EF代码的小应用程序,我想从package manager控制台调用update database命令,并以我的app.config(一个本地的.mdf)中的数据库为目标 我的app.config中有此连接字符串 错误消息 我认为我的设置错误,因此无法找到Events.mdf。有人知道我需要更改什么吗?您应该始终检查是否使用了正确的项目来应用更新,以从package manager控制台顶部的默认项目下拉列表中选择正确的项目,或者可以将-ProjectName添加到更新数据

我正在首先创建一个带有EF代码的小应用程序,我想从package manager控制台调用update database命令,并以我的app.config(一个本地的.mdf)中的数据库为目标

我的app.config中有此连接字符串

错误消息


我认为我的设置错误,因此无法找到Events.mdf。有人知道我需要更改什么吗?

您应该始终检查是否使用了正确的项目来应用更新,以从package manager控制台顶部的默认项目下拉列表中选择正确的项目,或者可以将-ProjectName添加到更新数据库命令中:

<connectionStrings>
    <add name="EventsConnectionString"
    connectionString="Data Source=(localdb)\v11.0;Database=EventsApp;Trusted_Connection=Yes;" />
  </connectionStrings>
using System.Data.Entity;
using EventsApp.Entities;

namespace EventsApp.Contexts.DataContexts
{
    public class RegistrantDb :DbContext
    {
        public RegistrantDb()
            : base("EventsConnectionString")
        {

        }

        public DbSet<Registrant> Registrants { get; set; }
    }
}
Update-Database -ConfigurationTypeName EventsApp.Contexts.DataContexts.RegistrantMigrations.Configuration -verbose
Error Number:-1,State:0,Class:20
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Update-Database -ProjectName EventsApp.Contexts -YourOtherOptions