EF使用CodeFirst,当使用localDB时,删除mdf文件,会报“Cannot attach the file ‘{0}' as database '{1}'”错误。解决方法如下:1、打开Visual Studio 命令提示2、sqllocaldb.exe stop v11.03、sqllocaldb.exe delete v11.0然后重新生成数据库文件即可