zoukankan      html  css  js  c++  java
  • 动态创建分页 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); }
  • 相关阅读:
    流式布局
    发送短信验证码 倒计时
    jQuery-qrcode.js 生成带Logo 的二维码
    bootstrap-daterangepicker插件运用
    html 转 pdf
    input placeholder 在chrome 浏览器自动填充时,背景色覆盖原有背景图片问题。
    jQuery.qrcode 生成二维码,并使用 jszip、FileSaver 下载 zip 压缩包至本地。
    java学习之super、final、static关键字及匿名对象
    java学习之数组
    java学习之循环语句
  • 原文地址:https://www.cnblogs.com/520cc/p/3198083.html
Copyright © 2011-2022 走看看