/// <summary> /// 清空数据库 /// </summary> public void ClearLotteryDB() { using (var lotterysEntities = new LotterysEntities()) { foreach (Lottery lottery in lotterysEntities.Lotterys) { lotterysEntities.Lotterys.Remove(lottery); } lotterysEntities.SaveChanges(); } }
/// <summary> /// 初始化DB /// </summary> private void initDB() { using (var lotterysEntities = new LotterysEntities()) { int initialId = int.Parse(ConfigurationManager.AppSettings["initialId"]); // 非空库 if (lotterysEntities.Lotterys.Count<Lottery>() != 0) { initialId = lotterysEntities.Lotterys.Max(l => l.ID) + 1; } loadHistoryLottery(initialId, lotterysEntities); lotterysEntities.SaveChanges(); } }