efcore icon indicating copy to clipboard operation
efcore copied to clipboard

SQL Server geography elevation (Z) is not updated

Open Dimigergo opened this issue 1 year ago • 7 comments

This is a simple example: EFCore6GeographyElevation.zip

Please make a db with the contained db.sql file, and run the application! error

EF Core version: 6.0.31 Database provider: (Microsoft.EntityFrameworkCore.SqlServer) Target framework: (.NET 6.0) Operating system: IDE: (e.g. Visual Studio 2022 17.10.4)

Dimigergo avatar Jul 25 '24 10:07 Dimigergo

I'm not able to repro this. Adding Console.WriteLine(db.Tbls.OrderBy(o => o.Id).Last().Coordinates.AsText()); at the end prints POINT Z(47.2 19.3 10.3)

AndriySvyryd avatar Aug 16 '24 20:08 AndriySvyryd

Wait, wait!

It is ok, that the db.Tbls.OrderBy(o => o.Id).Last().Coordinates.AsText() is good, but in the database it is wrong, not updated.

Thanks.

Dimigergo avatar Aug 27 '24 12:08 Dimigergo

@Dimigergo you're going to have to provide clear instructions to explain what you think is going wrong.

roji avatar Aug 27 '24 13:08 roji

After code line 31 db.SaveChanges() in the database, please run this script:

SELECT Id
      ,Coordinates.Lat
      ,Coordinates.Long
      ,Coordinates.Z
  FROM tbl

You will see that the Z value is still 100.3 rather than 10.3

Dimigergo avatar Aug 27 '24 14:08 Dimigergo

I believe that this should be re-opened. The thing that I notice is that the change tracker does not pick up a change to only the Z value. If I change a Z value and say a latitude, the change tracker marks the entity state as Modified. But if you only change the Z value, the entity state is still Unchanged.

andersme avatar Dec 02 '24 16:12 andersme

@andersme or anyone else, can you please put together a quick code sample we can use to repro the bug? A minimal, runnable console program would be ideal.

roji avatar Dec 02 '24 17:12 roji

Reopening as the original repro posted above does in fact reproduce the issue. That is, that changes in Z are not detected:

Tbl {Id: 1} Unchanged
  Id: 1 PK
  Coordinates: 'POINT Z(47.2 19.3 100.3)'

After change and calling DetectChanges:

Tbl {Id: 1} Unchanged
  Id: 1 PK
  Coordinates: 'POINT Z(47.2 19.3 10.3)'

This is likely because the comparison used on the type does not consider Z values. This might be an NTS thing, or it might be an EF thing, or a bit of both.

ajcvickers avatar Dec 04 '24 10:12 ajcvickers