/// <summary>
/// DB First 獲取連接字符串
/// </summary>
public ClientEntities()
: base("name=ClientEntities")
{
base.Database.Connection.ConnectionString = AppConfig.DataBaseConnectionString();
}
/// <summary>
/// Code First定義
/// </summary>
/// <param name="con"></param>
public ClientEntities(System.Data.Common.DbConnection con):base(con, contextOwnsConnection:false)
{
//詳見書196
}
//Code First用法
//var con = new SqlConnection(AppConfig.DataBaseConnectionString());
//dbContext = new ClientEntities(con);
//DB First 用法
dbContext = new ClientEntities();
/// <summary>
/// 獲取entity模型數(shù)據(jù)庫(kù)連接
/// </summary>
/// <returns></returns>
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 string.Concat("data source=" + DataSource + ";initial catalog=" + DataBase + ";persist security info=True;user id=" + UserId + ";password=" + PassWord + ";MultipleActiveResultSets=True;App=EntityFramework");
}
加密解密的就自己發(fā)揮啦,網(wǎng)上很多很多!F谆唷!