本文整理汇总了C#中PagedList.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# PagedList.Contains方法的具体用法?C# PagedList.Contains怎么用?C# PagedList.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PagedList
的用法示例。
在下文中一共展示了PagedList.Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchLogs
public PagedList<Log> SearchLogs(LogSearchCriteria criteria)
{
if (criteria == null)
throw new ApplicationException("Search criteria is null.");
using (var context = GetContext())
{
IQueryable<Log> query = from log in context.Logs
join cl in context.CategoryLogs on log.LogId equals cl.LogId
join c in context.Categories on cl.CategoryId equals c.CategoryId
where c.CategoryName == criteria.Category
select log;
if (criteria.DateFrom != null)
query = query.Where(l => l.TimestampUtc >= criteria.DateFrom);
if (criteria.DateTo != null)
query = query.Where(l => l.TimestampUtc <= criteria.DateTo);
if (!string.IsNullOrEmpty(criteria.Title))
query = query.Where(l => l.Title == criteria.Title);
if (criteria.Severity > 0)
{
List<string> severities = new List<string>();
if ((criteria.Severity & (int)TraceEventType.Critical) != 0)
severities.Add(TraceEventType.Critical.ToString());
if ((criteria.Severity & (int)TraceEventType.Error) != 0)
severities.Add(TraceEventType.Error.ToString());
if ((criteria.Severity & (int)TraceEventType.Warning) != 0)
severities.Add(TraceEventType.Warning.ToString());
if ((criteria.Severity & (int)TraceEventType.Information) != 0)
severities.Add(TraceEventType.Information.ToString());
query = query.Where(l => severities.Contains(l.SeverityName));
}
query = query.SortBy(criteria.SortBy, criteria.SortByDesc);
PagedList<int> logViewIds = new PagedList<int>(query.Select(l => l.LogId), criteria.StartIndex, criteria.PageSize);
IQueryable<Log> secondQuery = context.Logs.Where(l => logViewIds.Contains(l.LogId));
Dictionary<int, Log> logs = (criteria.ShouldIncludeMessage
? secondQuery.Select(l => new LogToView
{
LogId = l.LogId,
TimestampUtc = l.TimestampUtc,
Message = l.FormattedMessage
})
: secondQuery.Select(l => new LogToView
{
LogId = l.LogId,
SeverityName = l.SeverityName,
Title = l.Title,
TimestampUtc = l.TimestampUtc,
Message = l.Message.Substring(0, criteria.MessageLength)
})).ToDictionary(l => l.LogId, l => (Log)l);
return logViewIds.Transform<Log>(id => logs[id]);
}
}
示例2: SearchExportLogs
public PagedList<KeyExportLog> SearchExportLogs(ExportLogSearchCriteria criteria)
{
using (var context = GetContext())
{
var query = context.KeyExportLogs.Where(log => log.ExportLogId >= 0);
if (criteria != null)
{
if (criteria.DateFrom != null)
query = query.Where(k => k.CreateDate >= criteria.DateFrom);
if (criteria.DateTo != null)
query = query.Where(k => k.CreateDate <= criteria.DateTo);
if (!string.IsNullOrEmpty(criteria.ExportTo))
query = query.Where(k => k.ExportTo.Contains(criteria.ExportTo));
if (criteria.ExportTypes != null && criteria.ExportTypes.Count() > 0)
query = query.Where(k => criteria.ExportTypes.Contains(k.ExportType));
if (!string.IsNullOrEmpty(criteria.CreateBy))
query = query.Where(k => k.CreateBy == criteria.CreateBy);
if (criteria.IsEncrypted != null && criteria.IsEncrypted.HasValue)
query = query.Where(k => k.IsEncrypted == criteria.IsEncrypted);
if (!string.IsNullOrEmpty(criteria.FileName))
query = query.Where(k => k.FileName.Contains(criteria.FileName));
query = query.SortBy(criteria.SortBy, criteria.SortByDesc);
}
PagedList<int> logIds = new PagedList<int>(query.Select(l => l.ExportLogId), criteria.StartIndex, criteria.PageSize);
Dictionary<int, KeyExportLog> dic = context.KeyExportLogs
.Where(l => logIds.Contains(l.ExportLogId)).ToDictionary(l => l.ExportLogId, l => l);
return logIds.Transform(id => dic[id]);
}
}