sql-server - 为什么 Entity Framework 忽略我的连接字符串?

标签 sql-server entity-framework entity-framework-5

我有一个连接字符串:

<add name="Gini" providerName="System.Data.SqlClient" connectionString="user id=user;Password=pa55;Data Source=server;Database=gini" />

我希望 EF 能够控制数据库的创建并通过迁移进行更新,因此我让它完全控制数据库。

我的联系人类如下所示:

public class GiniContext : DbContext
{
    public DbSet<UserSession> UserSessions { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add(new UserSessionConfiguration());
    }

    public GiniContext() : base("Gini")
    {
        Database.Create();
    }
}

我希望这会使用上面的用户名和密码在名为“server”的服务器上创建一个名为“gini”的数据库,但它是在 (LocalDB)\v11.0 实例上创建它。

我做错了什么?

最佳答案

如果您有两个项目,例如对象类库和引用它的 Web 应用程序。您需要在 Web 应用程序中添加从 app.config 到 web.config 的连接。

关于sql-server - 为什么 Entity Framework 忽略我的连接字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16695925/

相关文章:

MySQL 用户定义变量与 MSSQL-server 用户定义变量对比

sql - 从 sp_whoisactive 返回的值的单位是什么

c# - Entity Framework : Automatic migration failed on huge DB

Azure辅助角色异步接收消息: how long I should put the sleep for?(毫秒)

mysql - 根据现有列中的值在新列中插入值

sql - SQL Server 中的 FIFO 查询

c# - 如何修复执行多个 SQL 语句的超慢 EF/LINQ 查询

c# - Entity Framework Core 在 sleep 状态下留下许多连接

entity-framework - EF 5. “Automatic migration was not applied because it would result in data loss”-仅更改了列名

c# - 重构 Linq 代码和 "LINQ to Entities does not recognize the method"