标签:
edmx的构造函数:
public TestCheckUpdatesEntities(): base(Config.DataBaseConnectionString(), "TestCheckUpdatesEntities") { this.ContextOptions.LazyLoadingEnabled = true; OnContextCreated(); }
EF连接字符串模板类:
public class Config { public static string DataBaseConnectionString() { string DataSource = ConfigurationManager.AppSettings["Server"].ToString(); string DataBase = ConfigurationManager.AppSettings["DataBase"].ToString(); string UserId = ConfigurationManager.AppSettings["User"].ToString(); string PassWord = ConfigurationManager.AppSettings["Password"].ToString(); return ConnectionString(DataSource, DataBase, UserId, PassWord); } public static string ConnectionString(string DataSource, string DataBase, string UserId, string PassWord) { return string.Concat("metadata=res://*/ClientData.csdl|res://*/ClientData.ssdl|res://*/ClientData.msl;provider=System.Data.SqlClient;provider connection string=\"", "Data Source=" + DataSource + ";Initial Catalog=" + DataBase + ";User ID=" + UserId + ";Password=" + PassWord + ";MultipleActiveResultSets=True;\""); } }
配置文件:
<appSettings> <add key="Server" value="192.168.1.79" /> <add key="DataBase" value="TestCheckUpdates" /> <add key="User" value="sa" /> <add key="Password" value="zblx2880011" /> </appSettings>
标签:
原文地址:http://www.cnblogs.com/a849788087/p/5753573.html