对于使用 Mongo Db Driver for C# 进行查询,这些方法中的任何一种是否比另一种更优化?:
var partsLogs = MvcApplication.MongoLoggingDatabase.GetCollection("PartDetailLog") .FindAll()
.Where(x => x.UserId == UserId) .Select(x => new RecentActivityPartsLogDto { OemCode = x.Request.OemCode, OemPartCode = x.Request.OemPartCode, OemPartDescription = x.Request.OemPartDescription, TimeStamp = x.TimeStamp, UserId = x.UserId.ToString() }) .OrderByDescending(x => x.TimeStamp) .Skip(pageSize * (page - 1)) .Take(pageSize);
或者
var doc = new QueryDocument(); doc["UserId"] = UserId;
var partsLogs = MvcApplication.MongoLoggingDatabase.GetCollection("PartDetailLog")
.Find(doc) .Select(x => new RecentActivityPartsLogDto { OemCode = x.Request.OemCode, OemPartCode = x.Request.OemPartCode, OemPartDescription = x.Request.OemPartDescription, TimeStamp = x.TimeStamp, UserId = x.UserId.ToString()}) .OrderByDescending(x => x.TimeStamp) .Skip(pageSize*(page - 1)) .Take(pageSize);
还有其他建议可以使此查询更好吗?