【问题标题】:Error attaching DB file with 'update-database'使用“更新数据库”附加数据库文件时出错
【发布时间】:2013-10-01 16:48:27
【问题描述】:

错误:无法将文件“C:\Projects\eManager2\eManager.Web\App_Data\eManager.Web.Infrastructure.DepartmentDb.mdf”附加为数据库

Web.Config 中的连接字符串:

<add name="DefaultConnection" connectionString="Data Source=SFP\v11.0;Initial Catalog=aspnet-eManager.Web-20131001100714;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-eManager.Web-20131001100714.mdf" providerName="System.Data.SqlClient" />

Migrations 文件夹中的 MVC 实体框架 Configuration.cs 类:

namespace eManager.Web.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<eManager.Web.Infrastructure.DepartmentDb>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
        }

        protected override void Seed(eManager.Web.Infrastructure.DepartmentDb context)
        {
            context.Departments.AddOrUpdate
                (
                    d => d.Name,
                    new Domain.Department() { Name = "Engineering" },
                    new Domain.Department() { Name = "Sales" },
                    new Domain.Department() { Name = "Marketing" },
                    new Domain.Department() { Name = "Human Resources" }
                );
        }
    }

}

【问题讨论】:

    标签: asp.net-mvc entity-framework visual-studio-2012 sql-server-2008-r2


    【解决方案1】:

    确保“20131001100714.mdf”与您添加的迁移相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 2014-08-16
      • 2013-02-23
      • 2020-09-22
      • 1970-01-01
      • 2012-10-04
      相关资源
      最近更新 更多