I have a model like this:
Class1
{
public List<Class2> Class2List { get; set; }
}
Class2
{
public List<Class3> Class3List { get; set; }
}
Class3
{
public List<Class4> Class4List { get; set; }
}
Class4
{
public int Value { get; set; }
public DateTime CreateDate{ get; set; }
}
I need to find a list of items of Class4 which are between two dates. I try to use below code but I need to return list of type Class4:
public async Task<IList<Class1>> GetClass4BetweenDates(string Id, DateTime fromDate, DateTime toDate)
{
var builder = Builders<Class1>.Filter;
var filter = builder.Eq("Id", Id) & builder.Gte("Class2.Class3.Class4.CreateDate", fromDate) & builder.Lte("Class2.Class3.Class4.CreateDate", toDate);
return await _context.GetCollection<Class1>().Find(filter).ToListAsync();
}
I know this is wrong. I need to know the correct way