public void Delete<T>(T t) where T : class { using (codeFirstEntities context = new codeFirstEntities()) { context.Set<T>().Remove(t); } }
//得到单个实体信息 public T GetInfo<T>(Expression<Func<T, bool>> express) where T : class { using (codeFirstEntities context = new codeFirstEntities()) { return context.Set<T>().FirstOrDefault<T>(express); } }
//得到单个实体信息 public List<T> GetList<T>(Expression<Func<T, bool>> express, int PageIndex, int PageSize) where T : class { using (codeFirstEntities context = new codeFirstEntities()) { return context.Set<T>().Where(express).Skip(PageSize * PageSize).Take(PageSize).ToList(); } }
public T Insert<T>(T t) where T : class { using (codeFirstEntities entity = new codeFirstEntities()) { entity.Set<T>().Add(t); entity.SaveChanges(); return t; } }