• MVC 查询 删除


         public class CURDEntity<T> where T : BaseEntity
        {
            private MyContext ctx;
            public CURDEntity(MyContext UserContext)
            {
                this.ctx = UserContext;
            }
            /// <summary>
            /// 获取所有数据
            /// </summary>
            /// <returns></returns>
            public IQueryable<T> GetAll()
            {
                var allData= this.ctx.Set<T>().Where<T>(t => t.IsDeleted == false);
                return allData;
                //return ctx.<T>
            }
    
            public T GetTById(long Id)
            {
                var SingleData = this.ctx.Set<T>().Where(t => t.Id == Id).SingleOrDefault();
                return SingleData;
            }
            public IQueryable<T> GetDataByPager(int PageIndex, int PageSize)
            {
                return this.ctx.Set<T>().OrderBy(t=>t.CreateDateTime).Skip(PageIndex).Take(PageSize);
            }
    
    
            public bool DeleteById(int Id)
            {
                try
                {
                    GetTById(Id).IsDeleted = false;
                    this.ctx.SaveChanges();
                    return true;
                }
                catch 
                {
                    return false;
                }
            }
     public abstract  class BaseEntity
        {
            public long Id { get; set; }
            public DateTime CreateDateTime { get; set; }
            public bool IsDeleted { get; set; }
        }
    
     public  class Users:BaseEntity
        {
            public string Name { get; set; }
            public string LoginName { get; set; }
            public string LoginPassWord { get; set; }
            public string Email { get; set; }
    
            public int? Age { get; set; }
    
            public string Birthday { get; set; }
    
            public string Phone { get; set; }
    
    
        }
  • 相关阅读:
    IDEA激活方式(亲测有效)加汉化方式
    IDEA快捷键
    (转)RBAC权限模型——项目实战
    Nginx负载均衡策略
    nginx proxy_pass
    Nginx rewrite
    web cache server方案比较:varnish、squid、nginx
    LVS负载均衡工作模式和调度算法
    四层 七层负载均衡区别
    Nginx每天自动日志分割
  • 原文地址:https://www.cnblogs.com/lierjie/p/11964679.html
Copyright © 2020-2023  润新知