如何重写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")
        //{
        //}

附注:继承 EF DBContext 只会有一个地方,不知道的可以自己全文搜索

posted @ 2015-08-28 11:18  许大虾  阅读(5689)  评论(0编辑  收藏  举报