title: EF5, SQL Server, Longitude and Latitude
body: <p>I found that the best type to store lat and long in SQL Server is decimal (9,6) (ref. <a href="https://stackoverflow.com/questions/1196415/what-datatype-to-use-when-storing-latitude-and-longitude-data-in-sql-databases">What datatype to use when storing latitude and longitude data in SQL databases?</a>) and so I did</p>
  
  <pre><code>AddColumn("dbo.Table", "Latitude", c =&gt; c.Decimal(nullable: false, precision: 9, scale: 6));
  AddColumn("dbo.Table", "Longitude", c =&gt; c.Decimal(nullable: false, precision: 9, scale: 6));
  </code></pre>
  
  <p>SQL seems ok, everything is working, BUT when I insert / update a value, i.e. </p>
  
  <pre><code>lat = 44.5912853
  </code></pre>
  
  <p>it is saved like this:</p>
  
  <pre><code>44.590000
  </code></pre>
  
  <p>I checked the flow, and just before the update, my entity contains the correct value, so I don't think is related to my code, but to some round that EF / SQL does. Do you have any idea to avoid this?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>update [dbo].[Breweries]
  set [RankId] = @0, 
  [Name] = @1, 
  [Foundation] = null, 
  [DirectSale] = @2, 
  [OnlineSale] = @3, 
  [StreetAddress] = @4, 
  [StreetAddress1] = null, 
  [ZIP] = @5, 
  [City] = @6, 
  [Province] = @7, 
  [CountryCode] = @8, 
  [Latitude] = @9, 
  [Longitude] = @10, 
  [PIVA] = null, 
  [CodFiscale] = null
  where ([BreweryId] = @11)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/B7Ko3.png" alt="enter image description here"></p>
  
  <p><strong>POCO entity</strong></p>
  
  <pre><code>[Table("Breweries")]
  public class Brewery : ABrewery 
  {
    ....
    public decimal Latitude { get; set; }
    public decimal Longitude { get; set; }
  }
  </code></pre>
  
  <p><strong>SQL Profiler</strong></p>
  
  <pre><code>exec sp_executesql N'update [dbo].[Breweries]
  set [RankId] = @0, [Name] = @1, [Foundation] = null, [DirectSale] = @2, [OnlineSale] = @3, [StreetAddress] = @4, [StreetAddress1] = null, [ZIP] = @5, [City] = @6, [Province] = @7, [CountryCode] = @8, [Latitude] = @9, [Longitude] = @10, [PIVA] = null, [CodFiscale] = null
  where ([BreweryId] = @11)
  ',N'@0 int,@1 nvarchar(128),@2 bit,@3 bit,@4 nvarchar(256),@5 varchar(16),@6 nvarchar(64),@7 nvarchar(64),@8 nvarchar(128),@9 decimal(18,2),@10 decimal(18,2),@11 int',@0=2,@1=N'Davide',@2=0,@3=0,@4=N'Via Moscardini, 24',@5='zip',@6=N'city',@7=N'province',@8=N'ITA',
  
  @9=44.59,@10=11.05,@11=2
  </code></pre>
  
  <p>Thanks</p>