Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetTopologySuite: Select geography Point X or Y properties translates to wrong T-SQL #15346

Closed
dominikfoldi opened this issue Apr 13, 2019 · 3 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@dominikfoldi
Copy link

dominikfoldi commented Apr 13, 2019

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'. 

Steps to reproduce

// 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<Model> Models { get; set; }
}

// 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();

Further technical details

EF Core version: 2.2.3
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 1809
IDE: Visual Studio 2017 15.9.11

@dominikfoldi dominikfoldi changed the title NetTopologySuite: Cannot Select geography Point X or Y properties NetTopologySuite: Select geography Point X or Y properties translates to wrong T-SQL Apr 13, 2019
@ajcvickers ajcvickers added this to the 3.0.0 milestone Apr 15, 2019
@smitpatel smitpatel added verify-fixed This issue is likely fixed in new query pipeline. poachable and removed verify-fixed This issue is likely fixed in new query pipeline. labels May 26, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jun 28, 2019
@smitpatel smitpatel removed their assignment Aug 7, 2019
@bricelam bricelam self-assigned this Sep 4, 2019
@bricelam bricelam modified the milestones: Backlog, 3.1.0 Sep 4, 2019
@bricelam
Copy link
Contributor

bricelam commented Oct 9, 2019

This is translated correctly in the new query pipeline--the column type is preserved and it uses Lat instead of STX

@bricelam bricelam closed this as completed Oct 9, 2019
@bricelam bricelam added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. poachable propose-punt punted-for-3.0 labels Oct 9, 2019
@bricelam bricelam modified the milestones: 3.1.0, 3.0.0 Oct 9, 2019
@bricelam bricelam removed their assignment Oct 9, 2019
@developermj
Copy link

Will this issue be fixed in EF Core 2.x?

@bricelam
Copy link
Contributor

Unlikely. Do you want it to be even after #18141?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

No branches or pull requests

5 participants