泛型-增删改查
public IQueryable<T> GetEntitys(Expression<Func<T,bool>> lambdaWhere) { //context.UserInfoes.Where(lambdaWhere); return context.Set<T>().Where(lambdaWhere); } public int Add(T entity) { context.Set<T>().Add(entity); return context.SaveChanges(); } public int Delete(int id) { //通过ID查询这条实体 T entity = context.Set<T>().Find(id); context.Set<T>().Remove(entity); return context.SaveChanges(); } public int Update(T entity) { //设置当前实体的状态为修改 context.Entry(entity).State = System.Data.Entity.EntityState.Modified; return context.SaveChanges(); } //校验用户是否登录 public class BaseController:Controller { public bool IsCheckLogin = true; public static UserInfo BaseUserInfo{get;set;} protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); if(IsCheckLogin) { if(BaseUserInfo == null) { filterContext.HttpContext.Response.Redirect("/Login/Index"); } } } }