C# 如何在c中转换下面的mongodb命令?
如何在c中转换下面的MangoDB命令C# 如何在c中转换下面的mongodb命令?,c#,asp.net-mvc-4,mangodb,C#,Asp.net Mvc 4,Mangodb,如何在c中转换下面的MangoDB命令 db.Report.find({DateAndTime:{$gt: ISODate("2014-11-13T18:43:33.868Z"),$lt:ISODate("2014-11-14T23:43:33.868Z")}}) 您可以这样做: public List<Report> FindRports() { var reportContext = new ReportContext(); var builder = Buil
db.Report.find({DateAndTime:{$gt: ISODate("2014-11-13T18:43:33.868Z"),$lt:ISODate("2014-11-14T23:43:33.868Z")}})
您可以这样做:
public List<Report> FindRports()
{
var reportContext = new ReportContext();
var builder = Builders<Reprot>.Filter;
var filter = builder.Gt(x => x.GeneratedAtUtc, new DateTime(2014, 11, 13, 18, 43 ,33 ,868))
& builder.Lt(x => x.GeneratedAtUtc, new DateTime(2014, 11, 14, 18, 43, 33, 868));
var result = reportContext.ReportCollection.Find(filter).ToList();
return result;
}
你试过什么吗
var greaterThen = new DateTime(2014,11,13) //or as you want
var smallerThen = new DateTime(2014,11,13) //or as you want
var report = db.Report.Where(r => r.Created > greaterThen && r.Created < smallerThen).ToList();
使用propername:到目前为止您尝试了什么?是的,我尝试了上面的查询,但是在这种情况下它忽略了边界情况。您的mongoDB查询也会这样做吗?因为您使用的是GT,还是更好、更平等?如果是这样,您可以使用ar report=db.report.where=>r.Created>=greater然后&r.Created是的,我尝试了上面的查询,但在这种情况下它忽略了边界情况。