.sum() on TimeSpan result in InvalidQueryException

34 views
Skip to first unread message

Ivan Montilla

unread,
Nov 20, 2020, 11:06:50 AM11/20/20
to RavenDB - 2nd generation document database
I have this LINQ query:



In the line 10, record.Lasts is a TimeSpan, and the generated RQL query is:



There are some workaround to operate with TimeSpan in queries?

Ivan Montilla

unread,
Nov 20, 2020, 11:09:02 AM11/20/20
to RavenDB - 2nd generation document database
Sorry, the code was removed.

LINQ query:
from book in _session.Query<ConsumptionBook>()
where book.ServiceId == serviceId
where book.Period == period
select new ConsumptionBookResumeOutputModel
{
Calls = new ConsumptionBookResumeOutputModel.CallResume
{
Amount = book.CallsAmount,
Calls = book.Calls.Count,
Lasts = new TimeSpan(book.Calls.Sum(record => record.Lasts.Ticks))
}
}

Generated RQL:
from 'Vadavo/Telecom/ConsumptionBook' as book
where (book.ServiceId = "1217-A") and (book.Period = "152")
select {
    Calls : {Amount:book.CallsAmount,Calls:book.Calls.length,
    Lasts:new System.TimeSpan(book.Calls.map((function(record){return record.Lasts.Ticks;})).reduce(function(a, b) { return a + b; }, 0))},
    Messages : {Amount:book.MessagesAmount,Messages:book.Messages.length},
    Data : {Amount:book.DataAmount,Kilobytes:book.Data.map(function(record){return record.Kilobytes;}).reduce(function(a, b) { return a + b; }, 0)}, SpecialServices : {Amount:book.SpecialAmount,Services:book.Special.length}
}

Grisha Kotler

unread,
Nov 23, 2020, 12:06:15 PM11/23/20
to rav...@googlegroups.com
Hi Ivan,

TimeSpan isn't supported yet in projections.
You can track the status of this issue here:

In the meantime you can return the ticks in the projection:

public class ConsumptionBookResumeOutputModel
{
    public long Ticks { get; set; }

    public TimeSpan Lasts => new TimeSpan(Ticks);
}

Grisha Kotler
Team Leader   /   Hibernating Rhinos LTD
Skype:  grisha.kotler
Support:  sup...@ravendb.net
  


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/83c2c28f-b26f-49dd-b39e-304af364203cn%40googlegroups.com.

Ivan Montilla

unread,
Nov 25, 2020, 11:28:31 AM11/25/20
to RavenDB - 2nd generation document database
Hi Grisha, I see that the issue is solved and merged. Thank you!
Reply all
Reply to author
Forward
0 new messages