/// <summary> /// 获取指定条件下的实体集实体数量 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static int Count <T>(Func <T, bool> predicate) { try { using (JinchengDB2Entities _emdc = new JinchengDB2Entities()) { return(((IEnumerable <T>)_emdc.Set(typeof(T))).Where(predicate).Count()); } } catch (Exception ex) { //throw ex; return(0); } }
/// <summary> /// 获取实体列表 /// </summary> /// <param name="predicate"></param> /// <returns></returns> public static List <T> GetList <T>(Func <T, bool> predicate) { try { using (JinchengDB2Entities _emdc = new JinchengDB2Entities()) { DbSet Db_Set = _emdc.Set(typeof(T)); return(((IEnumerable <T>)Db_Set).Where(predicate).ToList()); } } catch (Exception ex) { //throw ex; return(new List <T>()); } }
/// <summary> /// 获取实体 /// </summary> /// <param name="predicate"></param> /// <returns></returns> public static T Get <T>(Func <T, bool> predicate) { try { using (JinchengDB2Entities _emdc = new JinchengDB2Entities()) { DbSet Db_Set = _emdc.Set(typeof(T)); return(((IEnumerable <T>)Db_Set).FirstOrDefault(predicate)); } } catch (Exception ex) { //throw ex; return(default(T)); } }
/// <summary> /// 获取实体集实体数量 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static int Count <T>() { try { using (JinchengDB2Entities _emdc = new JinchengDB2Entities()) { DbSet Db_Set = _emdc.Set(typeof(T)); return(Db_Set.Local.Count); } } catch (Exception ex) { //throw ex; return(0); } }
/// <summary> /// 删除实体列表 /// </summary> /// <param name="lisT"></param> /// <returns></returns> public static bool Remove <T>(List <T> lisT) { try { using (JinchengDB2Entities _emdc = new JinchengDB2Entities()) { DbSet Db_Set = _emdc.Set(typeof(T)); foreach (T temp in Db_Set) { Db_Set.Remove(temp); } return(_emdc.SaveChanges() > 0); } } catch (Exception ex) { //throw ex; return(false); } }
/// <summary> /// 根据Lamda表达式删除实体 /// </summary> /// <param name="predicate"></param> /// <returns></returns> public static bool Remove <T>(Func <T, bool> predicate) { try { using (JinchengDB2Entities _emdc = new JinchengDB2Entities()) { DbSet Db_Set = _emdc.Set(typeof(T)); List <T> entityList = ((IEnumerable <T>)Db_Set).Where(predicate).ToList(); foreach (T temp in entityList) { Db_Set.Remove(temp); } return(_emdc.SaveChanges() > 0); } } catch (Exception ex) { return(false); } }