Cannot create a projection from DbSet if the model has a property of Point geography type and we are constructing a new type which has a different shape. To construct that different shape we have to get the X or Y coordinates of the Point field. It will translate to to 'STX' or 'STY' instead of 'LONG' or 'LAT' in T-SQL.
Exception message:
Could not find property or field 'STX' for type 'Microsoft.SqlServer.Types.SqlGeography' in assembly 'Microsoft.SqlServer.Types'.
```c#
// Our datamodel
public class Model
{
public string Name { get; set; }
public int Age { get; set; }
public Point Location {get; set; }
}
// Our DbContext
public class ApplicationContext : DbContext
{
DbSet
}
// Dto as the new shape of the data in memory
public class Dto
{
public string Name { get; set; }
public PointDto Location {get; set; }
public class PointDto
{
public double Latitude { get; set; }
public double Longitude{ get; set; }
}
}
// After getting the DbContext run the query
context.Models.Select(m => new Dto
{
Name = m.Name,
Location = new PointDto
{
Longitude = m.Location.X,
Latitude = m.Location.Y
}
}).ToList();
```
EF Core version: 2.2.3
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 1809
IDE: Visual Studio 2017 15.9.11
This is translated correctly in the new query pipeline--the column type is preserved and it uses Lat instead of STX
Will this issue be fixed in EF Core 2.x?
Unlikely. Do you want it to be even after #18141?