zoukankan      html  css  js  c++  java
  • 泛型增删改查 江南

    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");
    			}
    		}
    	}
    }
    

      

  • 相关阅读:
    5.9上午
    5.4下午
    5.4上午
    5.2上午
    4.19下午
    4.18上午
    4.17下午
    4.17上午
    4.12下午
    4.13下午
  • 原文地址:https://www.cnblogs.com/zhao987/p/15632263.html
Copyright © 2011-2022 走看看