ダイナミック作成ページングLINQ+EF
13256 ワード
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);
}