title: Dapper unable to cast object of type 'Microsoft.SqlServer.Types.SqlGeography' to type 'System.Data.Entity.Spatial.DbGeography'
body: <p>I have EF configured with a <code>Location</code> field on my <code>User</code> table:</p>
  
  <pre><code> public DbGeography Location { get; set; }
  </code></pre>
  
  <p>However when I query my <code>User</code> table with: </p>
  
  <pre><code> user = connection.Query&lt;User&gt;("update [User] set LastOnline = @lastOnline output INSERTED.* where Username = @un",
                          new { lastOnline = DateTime.UtcNow, un = username }).First();
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Message=Error parsing column 122 (Location=POINT (-118.2436849
    34.0522342) - Object)   Source=Dapper   StackTrace:
           at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in
    d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 4045
           at Deserialize4650b5f0-d037-49ad-802e-8a9be95e8496(IDataReader )
           at Dapper.SqlMapper.d__11<code>1.MoveNext() in d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1572
           at System.Collections.Generic.List</code>1..ctor(IEnumerable<code>1 collection)
           at System.Linq.Enumerable.ToList[TSource](IEnumerable</code>1 source)
           at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable<code>1
    commandTimeout, Nullable</code>1 commandType) in
    d:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1443
           at App.Services.BrowseService.GetProfiles(ProfileSearchDto query, String username, Boolean isAdmin) in
    c:\PROJECTS\App\App-MAIN\App\Services\BrowseService.cs:line 330 
    InnerException: System.InvalidCastException
           HResult=-2147467262
           Message=Unable to cast object of type 'Microsoft.SqlServer.Types.SqlGeography' to type
    'System.Data.Entity.Spatial.DbGeography'.</p>
  </blockquote>
  
  <p>What is causing this?  </p>
  
  <p><strong>Update</strong></p>
  
  <p>Just for kicks, I tried using EF: </p>
  
  <pre><code>db.Database.SqlQuery&lt;User&gt;("bla bla")
  </code></pre>
  
  <p>And I get a different error:</p>
  
  <blockquote>
    <p>Message=No mapping exists from object type
    &lt;>f__AnonymousTypef`2[[System.DateTime, mscorlib, Version=4.0.0.0,
    Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String,
    mscorlib, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089]] to a known managed provider native
    type.   Source=System.Data</p>
  </blockquote>
  
  <p><em>goes bald</em></p>
  
  <p><strong>Conclusion</strong></p>
  
  <p>My app needs to search by radius and currently uses a naive lat/long boxed query.  I was trying to upgrade my implementation to use spatial types, but it looks like my tooling doesn't support this scenario.  Back to being naive I go.</p>