错误:无法将文件“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" }
);
}
}
}