overflow on DateTime

Topics: General, Troubleshooting
Feb 6, 2012 at 8:48 AM

Knowing that this is probably not a Orchard issue somebody might be able to give me some hints!
I took the Orchard Doc sample "Creating a module with a simple text editor" which worked fine
Then I adapted the same ample using a 'Date'(DateTime) field which (on ContentType => Create new Eve) causes below error:
          [SqlCeException (0x80004005): An overflow occurred while converting to datetime.]
          [GenericADOException: could not insert: [Eve.Models.EvePartRecord#113][SQL: INSERT INTO Eve_EvePartRecord (Evenement, Category, HomeTeam, GuestTeam, Date, DateToEnroll, TeeTime, Captain, Change, Comment, Id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]]
 
PS:
The 'date' field (on ContentType => Create new Eve) shows '01.01.0001 00:00:00' ; I would like to see something formatted like {0:dd-MM-yyyy}!
The EvePartRecord (sqlCE DB) shows all fields (right now NULLS; I guess due to the error this is correct)

There are all kind of threads discussing dateTime conversion - which didn't help!

? are there any special considerations on this subject in Orchard / SqlCE?

Below the relevant definitions.
Thanks for your time, ed

EditorTemplates/Part:
@model Eve.Models.EvePart
<fieldset>
    <label class="sub" for="Evenement">@T("Evenement")</label>
    @Html.TextBoxFor(m => m.Evenement, new { @class = "text" })<br />
   
    <label class="sub" for="Date">@T("Date")</label>
    @Html.TextBoxFor(m => m.Date)<br />
   
</fieldset>

Data Model:
namespace Eve.Models {
    public class EvePartRecord : ContentPartRecord {
        public virtual string Evenement { get; set; }
       
        public virtual DateTime Date { get; set; }
       
       }
   
    public class EvePart : ContentPart<EvePartRecord> {
              
        [Required]
        public string Evenement
        {
            get { return Record.Evenement; }
            set { Record.Evenement = value; }
        }
        etc.....

Migrations.cs:
    public int Create() {
   // Creating table EvePartRecord
   SchemaBuilder.CreateTable("EvePartRecord", table => table
    .ContentPartRecord()
    .Column("Evenement", DbType.String)
    
    .Column("Date", DbType.DateTime)
    
   );

Feb 11, 2012 at 11:42 AM

Make your DateTime in the Model nullable:

public virtual DateTime? Date { get; set; } 

Feb 11, 2012 at 6:51 PM

thank you ... this is weird but it did the job?
Is this an Orchard issue or SqlCE or .... ?! 
Somewhen I might have time to dig deeper , ed

Coordinator
Feb 11, 2012 at 10:59 PM

What do you mean "issue"? If you want a nullable date, you need to specify it. Sounds perfectly normal to me.

Feb 12, 2012 at 6:47 AM

Bertrand, 
my aplogies to accuse Orchard; .. I just didn't even know that there can a ? be used to make it nullable!?, ed

 

Nov 18, 2013 at 5:43 AM
Edited Nov 18, 2013 at 6:26 AM
I got the same issue and I have also entered '?' sign to make it nullable. But after I enter date from admin side it gives red color message that it is not valid format for Date time. I have entered "'18/11/2013 12:10:00 PM" . I just want to know what kind of format Orchard is following and if I do not enter any date in DateTime field, it works fine.