Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I also struck this problem. </p> <p><em><strong>The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value</em></strong> is a very un-useful error that one receives. </p> <p>To resolve the problem I had to do the following (Using the above example):</p> <p>One can find the Package Manager Console from -> Tools -> Library Package Manager -> Package Manager Console</p> <p>I enabled Database Migrations in Package Manager Console -> Enable-Migrations</p> <p>Then added the below code in the Controller Class:</p> <pre><code>public class Auction { public long Id { get; set; } public string Title { get; set; } public string Description { get; set; } public decimal StartPrice { get; set; } public decimal CurrentPrice { get; set; } // My Edit to the code Start --&gt; public Nullable&lt;DateTime&gt; StartTime { get; set; } public Nullable&lt;DateTime&gt; EndTime { get; set; }} // My Edit to the code Finish &lt;-- } </code></pre> <p>Then in the Models Class:</p> <pre><code>[HttpPost] // My Edit to the code Start --&gt; [DataType(DataType.Date)] [DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]] // My Edit to the code Finish &lt;-- public ActionResult Create(Auction auction) { // My Edit to the code Start --&gt; if(ModelState.IsValid) { // Only Apply the DateTime if the Action is Valid... auction.StartTime = DateTime.Now; } // My Edit to the code Finish &lt;-- var db = new EbuyDataContext(); db.Auctions.Add(auction); db.SaveChanges(); return View(auction); } </code></pre> <p>Then Add to the Database the changes in the Package Manager Console -> Add-Migration (Your Change goes here)</p> <p>Then run a Database Update in the Package Manager Console -> Update-Database</p> <p>Its important to see that the Data that the Database see's is correct in the above implementation:</p> <pre><code>E.G: 17/06/2013 12:00:00 AM </code></pre> <p>This error is an amazingly stupid error but it seems to have caught a lot of people out including my self. Now I know why this error occurs it seems that it is easy to fix and get around but why such a common issue would not be fixed in the last release of MVC is beyond my comprehension.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload