title: argument exception parameter value is out of range decimal
body: <p>In database <code>price</code> column is set to <code>decimal(20, 2)</code>.</p>
  
  <p>It means it can hold 18 digits before decimal and 2 digits after decimal point. Right?</p>
  
  <p>Now when I try to save value <code>12345678.00</code>, it says: <code>parameter value is out of range</code></p>
  
  <p>What I'm doing wrong?</p>
  
  <p><strong>Update:</strong></p>
  
  <pre><code>123456.00 is saved in db.
  1234567.00 gives exception
  </code></pre>
  
  <p><strong>Exception:</strong></p>
  
  <blockquote>
    <p>System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.ArgumentException: Parameter value '12345678.00' is out of range. at System.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateO0bj, Boolean isCommandProc, Boolean sync, TaskCompletionSource<code>1 completion, Int32 startRpc, Int32 startParam) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task&amp; task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource</code>1 completion, Int32 timeout, Task&amp; task, Boolean&amp; usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource<code>1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean&amp; usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.BeginExecuteNonQueryInternal(CommandBehavior behavior, AsyncCallback callback, Object stateObject, Int32 timeout, Boolean inRetry, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.BeginExecuteNonQueryAsync(AsyncCallback callback, Object stateObject) at System.Threading.Tasks.TaskFactory</code>1.FromAsyncImpl(Func<code>3 beginMethod, Func</code>2 endFunction, Action<code>1 endAction, Object state, TaskCreationOptions creationOptions) at System.Threading.Tasks.TaskFactory</code>1.FromAsync(Func<code>3 beginMethod, Func</code>2 endMethod, Object state) at System.Data.SqlClient.SqlCommand.ExecuteNonQueryAsync(CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter<code>1.GetResult() at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.&lt;ExecuteAsync&gt;d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.&lt;UpdateAsync&gt;d__0.MoveNext() --- End of inner exception stack trace --- at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.&lt;UpdateAsync&gt;d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Core.Objects.ObjectContext.&lt;ExecuteInTransactionAsync&gt;d__3d</code>1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Core.Objects.ObjectContext.d__39.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.d__9<code>1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Data.Entity.Core.Objects.ObjectContext.&lt;SaveChangesInternalAsync&gt;d__31.MoveNext() --- End of inner exception stack trace --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter</code>1.GetResult()</p>
  </blockquote>
  
  <p><strong>Update:</strong></p>
  
  <p>I created a new database and run migration to make sure that db column is exactly what I'm expecting, and here it is:</p>
  
  <p><a href="https://i.stack.imgur.com/7ZfYe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ZfYe.png" alt="enter image description here"></a></p>
  
  <p><strong>Complete code:</strong></p>
  
  <p>Ad.cs:</p>
  
  <pre><code>[Table("ad")]
  public class Ad
  {
          [Key, DatabaseGenerated(DatabaseGeneratedOption.None), Column("id")]
          public Guid Id { get; set; }
          [Column("price")]
          public decimal Price { get; set; }
          //other attributes
  }
  </code></pre>
  
  <p>DbMigration class:</p>
  
  <pre><code>public partial class added_price_to_ad : DbMigration
      {
          public override void Up()
          { 
              AddColumn("dbo.ad", "price", c =&gt; c.Decimal(nullable: false, precision: 20, scale: 2));
          }
  
          public override void Down()
          { 
              DropColumn("dbo.ad", "images_count");
          }
      }
  </code></pre>
  
  <p>AdVm.cs:</p>
  
  <pre><code>public class AdVm
      {
          public string Id { get; set; }
          [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = 
          "{0:#.#}")]
          public decimal Price { get; set; }
          //other attributes
      }
  </code></pre>
  
  <p>create.cshtml:</p>
  
  <pre><code>@model ProjectName.ViewModels.AdVm
  @using (Html.BeginForm("Save", "Ads", FormMethod.Post, new { id = "CreateAdForm" }))
                      {
                          @Html.AntiForgeryToken()
  
                          &lt;div class="form-horizontal"&gt;
                              @Html.ValidationSummary(true)
                              @Html.HiddenFor(x =&gt; x.Id)
  
  &lt;div class="form-group"&gt;
                                  @Html.LabelFor(model =&gt; model.Price, new { @class = "control-label col-md-2" })
                                  &lt;div class="col-md-10"&gt;
                                      @Html.EditorFor(model =&gt; model.Price)
                                      @Html.ValidationMessageFor(model =&gt; model.Price)
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                          &lt;/div&gt;
                         &lt;input type="submit"/&gt;
                      }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    [HttpPost]
              [ValidateAntiForgeryToken]
      public async Task&lt;ActionResult&gt; Save(AdVm adVm)
     {
         var ad= Mapper.Map&lt;AdVm, Ad&gt;(adVm);
         db.Ads.Add(ad);
         await db.SaveChangesAsync(); //throws exception here
         return RedirectToAction("Details", new { id= ad.Id });
      }
  </code></pre>