title: How do I specify decimal precision using fluent api with Entity Framework and Code First?
body: <p>I have a solution that I'm using to test Fluent API.  When trying to set the precision on a decimal, the database is only updated correctly if I put the call in the OnModelCreating method and go through the entity.  When trying to use an EntityTypeConfiguration class, the database refuses to update.  MilesFromNearestAirport is the property in question.</p>
  
  <p>Lodging Model</p>
  
  <pre><code>Public Class Lodging
      Public Property LodgingId As Integer
      Public Property MilesFromNearestAirport As Decimal
  End Class
  </code></pre>
  
  <p>DBContext Class</p>
  
  <pre><code>    Public Class BreakAwayContext
          Inherits DbContext
  
          Public Property Lodgings As DbSet(Of Lodging)
          Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
              modelBuilder.Configurations.Add(New LodgingConfiguration)
          End Sub
      End Class
  </code></pre>
  
  <p>Lodging Configuration Class</p>
  
  <pre><code>Public Class LodgingConfiguration
      Inherits EntityTypeConfiguration(Of Lodging)
  
      Public Sub LodgingConfiguration()
          [Property](Function(l) l.MilesFromNearestAirport).HasPrecision(8, 1)
      End Sub
  
  End Class
  </code></pre>
  
  <p>I'm using a console app for testing.  Here is the Sub Main ()</p>
  
  <pre><code>Sub Main()
      Database.SetInitializer(New DropCreateDatabaseAlways(Of BreakAwayContext))
  End Sub
  </code></pre>
  
  <p>As you can see, I am dropping and recreating the database each run, regardless of changes to the models.  If I put the decimal precision configuration setting in the OnModelCreating method, all is well.</p>
  
  <pre><code>    Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
          modelBuilder.Entity(Of Lodging).Property(Function(l) l.MilesFromNearestAirport).HasPrecision(8, 1)
      End Sub
  </code></pre>
  
  <p>Are there any restrictions to using the EntityTypeConfiguration or does anyone have any suggestions on where I may have gone wrong?  I was going to post pictures of the resulting database table, but I'm not able to post images due to my reputation points.  Please let me know if you would like anymore information about the classes, solutions, environment etc.  I'm using EF6, .NET4, VB.NET, and SQL Server Express.</p>