简体   繁体   English

实体框架将小数点分隔符从传递的值更改为 FromSqlRaw

[英]Entity Framework changes decimal separator from passed values to FromSqlRaw

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? ""POINT(-1741541,25" <-- 几何中 position 17 的解析错误" 显然,它将 -1741541.25 更改为 -1741541,25,并且它以某种方式与语言环境设置相关联。但是,我的数据库语言环境是 en-US,因此这不是数据库的问题,但我应该以某种方式配置我的实体框架,但我不知道该怎么做,也找不到它。我该怎么办?

UPD : lat and lng are of type double (eg -1741541.255287818) UPDlatlngdouble类型(例如 -1741541.255287818)

I've also tried to do that using FromSqlInterpolated我也尝试使用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" ""POINT(@p" <-- 几何中 position 8 处的解析错误"

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.每当我将这些latlng值传递到查询字符串中时,它都可以正常工作。

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) .您可以强制使用带有.ToString(CultureInfo.InvariantCulture)的点分隔符来格式化 lat 和 lng。

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 .我不太确定,我猜问题出在正在运行的 Windows 区域设置/文化,因为我知道在我所在的地区 - 在我的开发机器上 - 小数点分隔符是, , not . . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM