如何重写EF DBContext 获取链接字符串的方法
展开全部
public partial class byvarDBFirst: DbContext
{
//使用自定义连接串
private static string GetEFConnctionString()
{
//string connString = "metadata=res://*/EFModel_FromDb.csdl|res://*/EFModel_FromDb.ssdl|res://*/EFModel_FromDb.msl;provider=System.Data.SqlClient;provider connection string=\"data source=localhost;initial catalog=leadmw2_ef;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework\"";
//string enString = SecurityHelper.DESEncrypt(connString);
//string enString = "4AA347EFAA33B94A6E197901484E3104608AB02A9E246BB73B0EB205881B7EE7B314D698E61A418E1F5619CFE648CC1E84F7E5BA7B450D5B396FA2D25EC7F93467DE6CF72CDD682EEF92DBC30A72A28416CC0328C39A6A8E5990E448D136D11FE42B9118C9A1039479504C92B75F0B9535A92F76E4705C31D33C9622517404DA585C2E9A1D8133B3971E1AB2FA64D5AF39BDC1D8852A2EA1E3F46C10FB3FDD058BDA0C1A8D52C5272866884F209D8113A8B5FC3D85625D202D2364C79FAC9E8C85C550743EF616EE3772EE55C06A5C11B968A4EF7193DD88F7E7B7984FD83067DE9B10967B31DE7B7352604F9FC65BA9720CD9D058DE28ECD269AB53D4F91004629BAE43BD184B762C202000CC9E62DB7D15BC77D1821FA3";
string enString = ConfigurationManager.AppSettings["customConnString"];
string connString = SecurityHelper.DESDecrypt(enString);
return connString;
}
public byvarDBFirst()
: base(GetEFConnctionString())
{
}
//public byvarDBFirst()
// : base("name=byvarDBFirst")
//{
//}
{
//使用自定义连接串
private static string GetEFConnctionString()
{
//string connString = "metadata=res://*/EFModel_FromDb.csdl|res://*/EFModel_FromDb.ssdl|res://*/EFModel_FromDb.msl;provider=System.Data.SqlClient;provider connection string=\"data source=localhost;initial catalog=leadmw2_ef;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework\"";
//string enString = SecurityHelper.DESEncrypt(connString);
//string enString = "4AA347EFAA33B94A6E197901484E3104608AB02A9E246BB73B0EB205881B7EE7B314D698E61A418E1F5619CFE648CC1E84F7E5BA7B450D5B396FA2D25EC7F93467DE6CF72CDD682EEF92DBC30A72A28416CC0328C39A6A8E5990E448D136D11FE42B9118C9A1039479504C92B75F0B9535A92F76E4705C31D33C9622517404DA585C2E9A1D8133B3971E1AB2FA64D5AF39BDC1D8852A2EA1E3F46C10FB3FDD058BDA0C1A8D52C5272866884F209D8113A8B5FC3D85625D202D2364C79FAC9E8C85C550743EF616EE3772EE55C06A5C11B968A4EF7193DD88F7E7B7984FD83067DE9B10967B31DE7B7352604F9FC65BA9720CD9D058DE28ECD269AB53D4F91004629BAE43BD184B762C202000CC9E62DB7D15BC77D1821FA3";
string enString = ConfigurationManager.AppSettings["customConnString"];
string connString = SecurityHelper.DESDecrypt(enString);
return connString;
}
public byvarDBFirst()
: base(GetEFConnctionString())
{
}
//public byvarDBFirst()
// : base("name=byvarDBFirst")
//{
//}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询