日期:2014-05-17 浏览次数:20564 次
using (var db = new WEBVODEntities())
{
var qry = db.Articles.AsQueryable(); //ObjectSet 转换成 IQueryable
if (typeId > 0)
qry = qry.Where(a => a.CategoryID == typeId); //文章类型(=0,就不进行类型筛选)
if (!showAll)
qry = qry.Where(a => a.Display && a.Approved); //!!!!(这个逻辑可能需要修改)showAll=false,只显示Display、Approved都等于True情况
if (!string.IsNullOrEmpty(title))
qry = qry.Where(a => a.Title.Contains(title)); //文章标题
if (!string.IsNullOrEmpty(author))
qry = qry.Where(a => a.Author.Contains(author)); //文章作者
PagedList<Article> pl = qry.OrderByDescending(a => a.PubDate).ToPagedList(pageIndex, pageSize);
foreach (var art in pl)
{
string LoginName = art.LoginName; //获取创建者ID
string RealName = db.RegisteredUsers.SingleOrDefault(a => a.LoginName == LoginName).RealName; //获取用户对象
art.LoginName = art.LoginName + "--" + RealName; &nb