• 动态创建分页 LINQ+EF


      
      public class Message
        {
            public int MessageId { get; set; }
            public string MessageTitle { get; set; }
            public string MessageContent { get; set; }
            public DateTime? MessageDate { get; set; }
            public string MessageType { get; set; }
            public int? MessageAuthorId { get; set; }
            public int MessageStart { get; set; }
            public int? ParentID { get; set; }
            public string remark { get; set; }
        }
    
    
        //总条数+数据
        public class MessageCount
        {
            public int count { get; set; }
            public List<Message> MessageList { get; set; }
        }


         /// <summary> /// 分页查询 /// </summary> public MessageCount getMessaggePage(string MessageId, string MessageTitle, string MessageContent, string MessageType, string MessageAuthorId, string MessageStart, string ParentID, string remark, int min, int max) { ZQSDWEBEntities2 ZQSDWEBEntities2 = new ZQSDWEBEntities2(); MessageCount messageCount = new MessageCount(); messageCount.count = ZQSDWEBEntities2.MessageDetail.Count<MessageDetail>(); //IEnumerable<Message> messageList = (from h in ZQSDWEBEntities2.MessageDetail // where h.ParentID == ParentID && h.MessageStart == MessageStart && // h.MessageAuthorId == MessageAuthorId && h.MessageContent == MessageContent&& // h.MessageId == MessageId&& // h.MessageTitle == MessageTitle && h.MessageType == MessageType&& // h.remark == remark // select new mode.Message() // { // MessageId = h.MessageId, // MessageAuthorId = h.MessageAuthorId, // MessageContent = h.MessageContent, // MessageDate = h.MessageDate, // MessageStart = h.MessageStart, // MessageTitle = h.MessageTitle, // MessageType = h.MessageType, // ParentID = h.ParentID, // remark = h.remark // }).OrderBy(h=>h.MessageId).Skip<Message>(min).Take<Message>(max); IQueryable<MessageDetail> odj = ZQSDWEBEntities2.MessageDetail; try { if (MessageId != null) { int tem = Convert.ToInt32(MessageId); odj = odj.Where(M => M.MessageId == tem); } if (MessageTitle != null) { odj = odj.Where(M => M.MessageTitle.StartsWith(MessageTitle)); } if (MessageContent != null) { odj = odj.Where(M => M.MessageContent.StartsWith(MessageContent)); } if (MessageType != null) { odj = odj.Where(M => M.MessageType == MessageType); } if (MessageAuthorId != null) { int tem = Convert.ToInt32(MessageAuthorId); odj = odj.Where(M => M.MessageAuthorId == tem); } if (MessageStart != null) { int tem = Convert.ToInt32(MessageStart); odj = odj.Where(M => M.MessageStart == tem); } if (ParentID != null) { int tem = Convert.ToInt32(ParentID); odj = odj.Where(M => M.ParentID == tem); } if (remark != null) { odj = odj.Where(M => M.remark == remark); } odj = odj.OrderBy(Math => Math.MessageId).Skip(min).Take(max); } catch (Exception ex) { throw ex; } messageCount.MessageList = (from h in odj select new Message() { MessageId = h.MessageId, MessageAuthorId = h.MessageAuthorId, MessageContent = h.MessageContent, MessageDate = h.MessageDate, MessageStart = h.MessageStart, MessageTitle = h.MessageTitle, MessageType = h.MessageType, ParentID = h.ParentID, remark = h.remark }).ToList(); return messageCount; // 拉姆达表达式 // adapter.GetData().Select(d=>new Customer(){ID=d.ID,...}) //List<MessageDetail> MessageDetails = ZQSDWEBEntities2.MessageDetail.Where<MessageDetail>(M => M.ParentID == PrentId && M.MessageStart == 1).ToList<MessageDetail>(); // return JsonConvert.SerializeObject(MessageDetails, Formatting.None); }
  • 相关阅读:
    Android Gallery和ImageSwitcher同步自动(滚动)播放图片库
    Android PullToRefreshListView和ViewPager的结合使用
    AndroidTagView云标签
    Android 两步搞定Fragment的返回键
    Android Fragment数据传递与数据回显
    Glide加载圆形图片第一次只显示默认图片
    Android 自定义EditText实现类iOS风格搜索框
    TabLayout中Indicator的样式修改
    Kali linux2.0里Metasploit的服务类型探测
    Kali linux 2016.2(Rolling)中的Nmap的端口扫描功能
  • 原文地址:https://www.cnblogs.com/520cc/p/3198083.html
Copyright © 2020-2023  润新知