您可以只打开您的项目web.config
文件或app.config
文件,然后更新您的实体框架连接字符串以引用您需要的 SQL Server 实例,如下所示:
<add name="DefaultConnection" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=YourServerInstance;Initial Catalog=YourDB;Persist Security Info=True;User ID=sa;Password=123456;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
通过检查上下文类以检查它引用的连接字符串键名,确保您正在编辑正确的连接字符串:
public YourContext(bool lasyLoadingEnabled) : base("DefaultConnection")
{
Database.SetInitializer<NimasContext>(null);
this.Configuration.LazyLoadingEnabled = lasyLoadingEnabled;
this.Configuration.ProxyCreationEnabled = false; ;
}
您可以点击此链接:
https ://msdn.microsoft.com/en-us/library/jj556606(v=vs.113).aspx