0

对于使用 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);

还有其他建议可以使此查询更好吗?

4

1 回答 1

0

第一个将拉回每个文档并在客户端过滤它,第二个将过滤文档服务器端并仅拉回匹配的文档。使用第二个。

于 2012-05-22T06:07:49.113 回答