/// <summary> /// 保存数据到数据库 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> public static void saveDataToSql <T>(List <T> a) where T : class { if (a.Count < 1) { return; } EnumDBContext db = new EnumDBContext(); var lt = db.Set <T>(); var ps = typeof(T).GetProperties(); PropertyInfo pi = ps.FirstOrDefault(c => c.Name == "ID"); foreach (T item in a) { T m = lt.FirstOrDefault(c => (Int32)pi.GetValue(item) == (Int32)pi.GetValue(c)); if (m == null) { lt.Add(item); } else { cltocl <T>(item, ref m, new List <string>() { "ID" }); } } db.SaveChanges(); db.Dispose(); }
/// <summary> /// 获取数据集合 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static List <T> getListFromSQL <T>() where T : class { EnumDBContext ec = new EnumDBContext(); var Sourcelist = ec.Set <T>().ToList(); ec.Dispose(); string className = typeof(T).Name; if (!PubulicData.sourceData.Keys.Contains(className)) { PubulicData.sourceData.Add(className, Sourcelist); } else { PubulicData.sourceData[className] = Sourcelist; } return(Sourcelist); }
public void reSetIndex() { EnumDBContext dbc = new EnumDBContext(); var btndate = dbc.Set <ButtonDate>(); var btnWeb = btndate.Where(c => c.Type == BtnType.网站.ToString()).OrderBy(c => c.Index); var btnApp = btndate.Where(c => c.Type == BtnType.链接.ToString()).OrderBy(c => c.Index); int index = 1; foreach (ButtonDate item in btnWeb) { item.Index = index; index++; } index = 1; foreach (ButtonDate item in btnApp) { item.Index = index; index++; } dbc.SaveChanges(); dbc.Dispose(); }