错误:无法将文件'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" />
迁移文件夹中的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" }
);
}
}
}
答案 0 :(得分:0)
确保“ 20131001100714.mdf”与您添加的迁移相同。