1、将数据库文件放到App_Data文件夹下
2、Web.config连接字符串配置
<add name="TestEntities" connectionString="Data Source=(localdb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|Test.mdf;Initial Catalog=Test;Integrated Security=True" />
EF(dbfirst、modelfirst)的配置
<add name="TestEntities" connectionString="metadata=res://*/Models.TestModel.csdl|res://*/Models.TestModel.ssdl|res://*/Models.TestModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(localdb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|Test.mdf;initial catalog=Test;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
EF (codefirst)的配置
<add name="TestEntities" connectionString="Data Source=(localdb)MSSQLLocalDB;AttachDbFilename=|DataDirectory|Test.mdf;Initial Catalog=Test;Integrated Security=True" providerName="System.Data.SqlClient"/>
Data Source为使用localdb的版本
3、更改IIS中应用程序池中高级中的标识为LocalSystem