I have a collection of planning with a startDate and a duration in hours (totalDuration)
public class PlanningDTO
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId Id { get; set; }
[BsonElement("startDate")]
public DateTime StartDate { get; set; }
[BsonElement("totalDuration")]
public int TotalDuration { get; set; }
}
I want to get the planning that are included in a date range.
I am using an API in .Net 3.1 with MongoDriver 2.12.3
I have tried things like:
GetPlanningsInDateRange(DateTime startDate, DateTime endDate){
var filter = Builders<PlanningDTO>
.Filter
.Where(pp => pp.StartDate.AddHours(pp.TotalDuration) >= startDate && pp.StartDate <= endDate);
var planningsInRange = await Db.GetCollection<PlanningDTO>("Plannings").Find(filter).ToListAsync();
return planningsInRange;
}
or using Mongo.Driver.LINQ
var planningsInRange = await Db.GetCollection<PlanningDTO>("Plannings").AsQueryablew<PlanningDTO>()
.Where(pp => pp.StartDate.AddHours(pp.TotalDuration) >= startDate && pp.StartDate <= endDate).ToListAsync();
but what i get is en error:
System.InvalidOperationException: {document}{startDate}.AddHours(Convert({document}{totalDuration}, Double)) is not supported.
If i do this kind of query without AddHours(), it works fine (no error) but then it is not what i want.
Any idea?