泛型-增删改查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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");
            }
        }
    }
}

  

posted @   江南-烟雨  阅读(63)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示