首页 > Web开发 > 详细

MVC 查询 删除

时间:2019-12-01 00:30:27      阅读:73      评论:0      收藏:0      [点我收藏+]
     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; }


    }

 

MVC 查询 删除

原文:https://www.cnblogs.com/lierjie/p/11964679.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!