cannot convert type 'System.Datetimeoffset' to 'System.DateTime?'

536 views
Skip to first unread message

Lee

unread,
Jun 4, 2013, 10:24:36 AM6/4/13
to rav...@googlegroups.com
Hi,

Moving from Raven v427 to the latest build and i have smuggled the data out and smuggled it into the new version.

However i am encountering issues with DateTime? in an index and getting "cannot convert type 'System.Datetimeoffset' to 'System.DateTime?'" errors in the index.

Here is the Index:

Map = docs => from doc in docs

                          where (doc.ResourceType == "Hub" &&

                                 doc.IsDeleted == false &&

                                 !doc.Id.EndsWith("/published") &&

                                 !doc.Id.Contains("/revisions/"))                                          

                          select new

                                     {

                                         doc.Id,

                                         doc.LastEditedBy,

                                         doc.LastEditedOn,

                                         doc.Title,

                                         doc.TitleForSorting,

                                         doc.Source,                                  

                                         doc.ResourceType,

                                         Publisher = doc.Publisher.Length == 0 ? new[] {"UNSET"} : doc.Publisher,

                                         doc.CreatedBy,

                                         doc.CreatedOn,

                                         doc.LastPublishedOn,

                                         doc.Status, 

                                         ExpiryDate = doc.ExpiryDate ?? new DateTime(1902, 01, 01), 

                                         ReviewDate = doc.ReviewDate ?? new DateTime(1902, 01, 01),

                                         doc.SubjectArea,

                                         doc.PublicationType,

                                         AreaOfInterest = doc.AreaOfInterest ?? new [] {"UNSET"},

                                         doc.Topic,

                                         PublicationDate = doc.PublicationDate ?? new DateTime(1902,01,01)

                                     };


Note when you remove the ExpiryDate, ReviewDate and PublicationDate it works ok, its seems that the documents are being stored different now?

Here is the fields in an example document that blows up:

"PublicationDate": "2009-06-02T01:00:00.0000000+01:00",

"ReviewDate": "2011-08-06T01:00:00.0000000+01:00",

"ExpiryDate": "",

Is there anything i am doing wrong?

Regards,

Lee



Oren Eini (Ayende Rahien)

unread,
Jun 4, 2013, 10:35:09 AM6/4/13
to ravendb
Yes, one of the differences along the way was the way we handle date time formatting.
You probably want to register a converter to handle that issue.


--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Lee

unread,
Jun 4, 2013, 10:37:50 AM6/4/13
to rav...@googlegroups.com
do you have an example i could follow?

Thanks

Lee

Oren Eini (Ayende Rahien)

unread,
Jun 4, 2013, 10:39:16 AM6/4/13
to ravendb

Lee Smith

unread,
Jun 4, 2013, 10:48:27 AM6/4/13
to rav...@googlegroups.com
So just to make sure im on the right path...

I implement a JsonConverter and register it against the document store at start up, then smuggle in the documents so they get written correctly in the new format?

In that JsonConverter i convert the existing DateTimeOffsets of a record to Datetime?

Regards,

Lee


--
You received this message because you are subscribed to a topic in the Google Groups "ravendb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/pENFQOng6nE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.

Fitzchak Yitzchaki

unread,
Jun 5, 2013, 7:31:27 AM6/5/13
to <ravendb@googlegroups.com>
Register this converter in your application's DocumentStore.
You do not must to re-save all the docs, as you can do that, sure.
Reply all
Reply to author
Forward
0 new messages