日期:2014-05-18 浏览次数:20411 次
#region ITemplateQuery<news> 成员 public List<news> TemplateQuery(news queryTemplate) { using (var context = new DataClasses1DataContext(DBHelper.GetConnectionString())) { var query = this.GetQuery(queryTemplate, null, null, context); return query.OrderByDescending(u => u.news_id).ToList(); } } public List<news> TemplateQuery(int startIndex, int pageSize, ref int count, news queryTemplate, DateTime? startDate, DateTime? endDate) { using (var context = new DataClasses1DataContext(DBHelper.GetConnectionString())) { var query = this.GetQuery(queryTemplate, startDate, endDate, context); count = query.Count(); return query.OrderByDescending(u => u.news_id).Where(u=>u.news_class!=null).Skip(startIndex * pageSize).Take(pageSize).ToList(); } } private IQueryable<news> GetQuery(news queryTemplate, DateTime? startDate, DateTime? endDate, DataClasses1DataContext context) { var query = context.news.AsQueryable(); if (!string.IsNullOrEmpty(queryTemplate.news_title)) { query = query.Where(u => u.news_title.Contains(queryTemplate.news_title)); } if (!string.IsNullOrEmpty(queryTemplate.news_author)) { query = query.Where(u => u.news_author.Equals(queryTemplate.news_author)); } if (!string.IsNullOrEmpty(queryTemplate.news_editor)) { query = query.Where(u => u.news_editor.Equals(queryTemplate.news_editor)); } if (queryTemplate.news_class != null) { query = query.Where(u => u.news_class == queryTemplate.news_class); } if (startDate != null) { query = query.Where(u => u.news_date >= startDate.GetValueOrDefault()); } if (endDate != null) { query = query.Where(u => u.news_date <= endDate.GetValueOrDefault()); } return query; } #endregion