Projection in nullable types produces a bad query

32 views
Skip to first unread message

Ivan Montilla

unread,
Nov 13, 2019, 5:42:26 AM11/13/19
to RavenDB - 2nd generation document database
Hi, I'm doing this projection;

query.Select(x => new UpdateModel
{
    FirstName = x.FirstName,
    LastName = x.LastName,
    Email = x.Email,
    EmailConfirmed = x.EmailConfirmed,
    Document = x.Document.Value,
    DocumentType = x.Document.Type.ToString(),
    BirthDay = x.BirthDate != null ? x.BirthDate.Value.Day : (int?) null,
    BirthMonth = x.BirthDate != null ? x.BirthDate.Value.Month : (int?) null,
    BirthYear = x.BirthDate != null ? x.BirthDate.Value.Year : (int?) null
})

Take attention in the three last properties, x.Birthdate is of type DateTime?, a nullable struct. That means, for accessing the DateTime object, I need to call x.BirthDate.Value or x.BirthDate? (these last syntax is not allowed into expression).

from [...]
where [...]
select {
    FirstName : x.FirstName,
    LastName : x.LastName,
    Email : x.Email, 
    EmailConfirmed : x.EmailConfirmed, 
    Document : x.Document.Value, 
    DocumentType : x.Document.Type.toString(), 
    BirthDay : x.BirthDate!=null?new Date(Date.parse(x.BirthDate.Value)).getDate():null,
    BirthMonth : x.BirthDate!=null?new Date(Date.parse(x.BirthDate.Value)).getFullYear():null,
    BirthYear : x.BirthDate!=null?new Date(Date.parse(x.BirthDate.Value)).getMonth()+1:null
}
limit [...]

The problem is that in the generated query, in Date.parse is trying to access to x.BirthDate.Value that doesn't exists, so its returns NaN. If I remove `.Value` in the parameter of Date.parse, returns the expected result.

Ivan Montilla

unread,
Nov 13, 2019, 5:49:53 AM11/13/19
to RavenDB - 2nd generation document database
I found this issue in youtrack, but state is fixed in 4.0 and I'm using 4.2.3

Grisha Kotler

unread,
Nov 13, 2019, 9:12:06 AM11/13/19
to rav...@googlegroups.com
Hi,

The issue is fixed and will be available in the next build.

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/fcaa71c1-1c09-4998-ae42-0a653e5d0205%40googlegroups.com.

Ivan Montilla

unread,
Nov 13, 2019, 9:17:32 AM11/13/19
to RavenDB - 2nd generation document database
To unsubscribe from this group and stop receiving emails from it, send an email to rav...@googlegroups.com.

Grisha Kotler

unread,
Nov 13, 2019, 9:22:23 AM11/13/19
to rav...@googlegroups.com
Yes.

A workaround would be to use the RQL expression without the ".Value" (from session.Advanced.RawQuery).


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

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/8c9895e2-d3c2-4db4-9969-186ad1bc5a87%40googlegroups.com.

Ivan Montilla

unread,
Nov 15, 2019, 4:41:54 AM11/15/19
to RavenDB - 2nd generation document database
Working as espected in 20191114 nightly.
Reply all
Reply to author
Forward
0 new messages