SQL Server geography elevation (Z) is not updated
This is a simple example: EFCore6GeographyElevation.zip
Please make a db with the contained db.sql file, and run the application!
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)
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)
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 you're going to have to provide clear instructions to explain what you think is going wrong.
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
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 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.
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.