EF使用CodeFirst,当使用localDB时,删除mdf文件,会报“Cannot attach the file ‘{0}' as database '{1}'”错误。

解决方法如下:

1、打开Visual Studio 命令提示

2、sqllocaldb.exe stop v11.0

3、sqllocaldb.exe delete v11.0

然后重新生成数据库文件即可

Cannot attach the file ‘{0}' as database '{1}'-LMLPHP

05-11 19:25