I try to execute the following query:
dbContext.Datas.FromSqlRaw($"select LD."Id", LD."OId" from public."Datas" LD where ST_Intersects(LD."Geometry", st_geomfromtext('POINT({lat} {lng})'))").Select(l => l.Id);
But whenever I’m doing it, I get the following error:
“”POINT(-1741541,25″ <– parse error at position 17 within geometry”
Obviously, it changes -1741541.25 to -1741541,25, and it’s somehow linked with locale settings. However, my database locale is en-US, therefore it’s not database’s problem, but I should somehow configure my Entity framework, but I’m not sure how to do it and couldn’t find it either. What should I do?
UPD: lat and lng are of type double (e.g -1741541.255287818)
I’ve also tried to do that using FromSqlInterpolated
dbContext.Datas.FromSqlInterpolated($"select LD."Id", LD."OId" from public."Datas" LD where ST_Intersects(LD."Geometry", st_geomfromtext('POINT({lat} {lng})'))").Select(l => l.Id);
But I get this error:
“”POINT(@p” <– parse error at position 8 within geometry”
Also I’m pretty much sure that my query is correct. Whenever I pass those lat and lng values into the query string, it works fine.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Went through the same situation this morning.
You can force both lat and lng to be formatted with a dot separator with .ToString(CultureInfo.InvariantCulture).
Updated after comment:
I’m not really sure, I guess the issue comes from the running Windows Regional settings / Culture as I know that in my region – and on my developing machine – the decimal separator is ,, not ..
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0