不将EF连接字符串写在配置文件的方法
2013-07-30 13:48
288 查看
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'");
}
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'");
}
相关文章推荐
- 【黑马程序员】连接字符串放在配置文件中方法(学习笔记)
- ASP.NET数据库连接字符串写在config.web配置文件中
- C#中配置文件的使用方法(连接字符串的保存)
- 使用Hibernate连接h2数据库的配置文件写的方法(连接字符串)
- Hibernate连接Mysql主配置文件方法(连接字符串)
- .net的EF框架中提示:在应用程序配置文件中找不到名为“****”的连接字符串。
- ASP.NET数据库连接字符串写在config.web配置文件中
- .NET的EF框架中:在应用程序配置文件中找不到名为“”的连接字符串问题
- 将LinqToSql的连接字符串写在配置文件中
- ASP.NET数据库连接字符串写在config.web配置文件中(2)
- ef在应用程序配置文件中找不到名为“Entities”的连接字符串。
- ASP.NET数据库连接字符串写在config.web配置文件中(1)
- [学习笔记]将LinqToSql的连接字符串写在配置文件中
- .NET的EF框架中:在应用程序配置文件中找不到名为“”的连接字符串问题
- 使用配置文件保存连接数据库的字符串的方法
- [导入]ASP.NET遍历配置文件的连接字符串
- DISCUZ! 7.2迁移服务器数据库连接文件配置方法
- [编辑][Java]删除properties配置文件中键值对的方法、附带字符串和Unicode间的转换方法
- .Net配置文件中的数据库连接字符串使用
- ASP.NET——配置文件——连接字符串