I created an Entity Data Model and got a WCF client-server app up and running. Now we're ready to test deploy, and the server should connect to a different database than it did during testing. I cannot find a way to change the database that the model hits.
I access the database in the following manner:
If I run it as is, it uses the original database I used when creating the EDM. I CAN change the database at run time by changing the code as follows:Code:List<PolicyBDO> policyBDOs = null; using (var PolicyEntities = new PolicyEntities()) { DateTime now = DateTime.Now; var policy = (from p in PolicyEntities.Table1 where p.Num.StartsWith(NumVal) && p.Type == TypeVal orderby p.Num,p.BeginDate select p); }
So I have a workaround, but I shouldn't NEED to do it that way. How can I change the database connection within the Entity Data Model itself, so that it automatically connects to the new database?Code:List<PolicyBDO> policyBDOs = null; using (var PolicyEntities = new PolicyEntities()) { String conn = PolicyEntities.Database.Connection.ConnectionString; PolicyEntities.Database.Connection.ConnectionString = conn.Replace("OldServer", "NewServer"); DateTime now = DateTime.Now; var policy = (from p in PolicyEntities.Table1 where p.Num.StartsWith(NumVal) && p.Type == TypeVal orderby p.Num,p.BeginDate select p); }




Reply With Quote
