简体   繁体   English

首先使用实体​​框架代码创建本地数据库

[英]Creating local database with Entity Framework Code First

I have problem with creating local db with EF code first. 我首先使用EF代码创建本地数据库时遇到问题。 When I try create db with command update-database Visual Studio returns the error: 当我尝试使用命令update-database创建update-database Visual Studio返回错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (提供者:SQL网络接口,错误:26-指定服务器/实例时出错)

In earlier project I haven't any problem with do that. 在较早的项目中,我这样做没有任何问题。

Context Class 上下文类

public class Context : DbContext {

    public DbSet<Project> Projects { get; set; }
    public DbSet<Task> Tasks { get; set; }
    public DbSet<Team> Teams { get; set; }
    public DbSet<User> Users { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        modelBuilder.Ignore<IIdentifableEntity>();

        modelBuilder.Entity<Project>().HasKey(p => p.Id).Ignore(p => p.EntityId);
        modelBuilder.Entity<Task>().HasKey(t => t.Id).Ignore(t => t.EntityId);
        modelBuilder.Entity<Team>().HasKey(t => t.Id).Ignore(t => t.EntityId);
        modelBuilder.Entity<User>().HasKey(u => u.Id).Ignore(u => u.EntityId);
    }

}

App.config App.config中

Thank you for any help. 感谢您的任何帮助。

Make sure your connection string is valid and working with the reference database associated with respective username and password. 确保您的连接字符串有效,并且可以使用与相应的用户名和密码关联的参考数据库。 You can check your database is connecting using SQL server management studio. 您可以使用SQL Server Management Studio检查数据库是否正在连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM