将字符串转换为十进制并与 Linq to NHibernate 3.1 进行比较

发布于 2024-11-11 16:25:15 字数 498 浏览 6 评论 0原文

我有一个像这样的表:

Name     Height
-------  ---------
Sam      "1.80"
Paul     "1.79"
Max      "1.81m"
Steve    "none"

我只想过滤身高 > 的人1.79。 为此,我必须转换为十进制然后进行比较。忽略非数字值,例如“none”。 我尝试了 Decimal.Parse() 和 Convert.ToDecimal() 但显示错误 System.NotSupportedException

peoples = peoples.Where(f => Convert.ToDecimal(f.Height) > 1.8);
peoples = peoples.Where(f => decimal.Parse(f.Height) > 1.8);

有解决方案吗?

Tks[]

帕特里克·科埃略

I have a table like:

Name     Height
-------  ---------
Sam      "1.80"
Paul     "1.79"
Max      "1.81m"
Steve    "none"

I want to filter only the peoples with height > 1.79.
To do this, I must convert to decimal and then compare. Ignoring the values ​​that are not numerical, such as "none".
I tryed Decimal.Parse() and Convert.ToDecimal() but show a error System.NotSupportedException

peoples = peoples.Where(f => Convert.ToDecimal(f.Height) > 1.8);
peoples = peoples.Where(f => decimal.Parse(f.Height) > 1.8);

Any solution??

Tks[]

Patrick Coelho

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯离梦残月幽梦 2024-11-18 16:25:15

使用 NH.Linq 将数据库中的非数字值与数字进行比较的唯一方法是:

  1. 将列转换为数字列
  2. 加载所有值并在内存中进行比较(对于大型数据库,不建议这样做)数据集。

The only way you will be able to compare the non-numeric values in the database against a number using NH.Linq is either:

  1. Convert the column to a numeric column
  2. Load all the values up and compare in memory (which is not recommended for big datasets.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文