edmx的构造函数:
public DecorationMSEntities() : base(myConfig.DataBaseConnectionString, "DecorationMSEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
EF连接字符串模板类:
public class myConfig
{
public static string DataBaseConnectionString
{
return
EFConnectionStringModle("EFname", @"(local)instance",
"yourDbName","sa","yourpassword"); }
}
private static string EFConnectionStringModle(string EntityName,string DBsoure,string DBname, string ID, string Password)
{
return string.Concat("metadata=res://*/",
EntityName, ".csdl|res://*/",
EntityName, ".ssdl|res://*/",
EntityName, ".msl;provider=System.Data.SqlClient;provider connection string='Data Source=",
DBsoure, ";Initial Catalog=",
DBname,";Persist Security Info=True;User ID=",
ID, ";Password=",
Password, ";MultipleActiveResultSets=True'");
}