如何通过linq按顺序转换列

发布于 2024-09-24 05:48:31 字数 180 浏览 0 评论 0原文

选择年份 来自我的桌子 Order By Cast( [Year] as Int ) Desc

我正在尝试在 linq order by 中做同样的事情。它不起作用。 我有在数据库中定义为字符串(Varchar)的列,在需要对其进行排序之前,我需要将其转换/转换为整数。我的 linq 语句应该是什么?

提前致谢。

Select Year
From MyTable
Order By Cast( [Year] as Int ) Desc

Same thing I am trying to do in the linq order by. It's not working.
I have column that is defined in the data base as string (Varchar) and I need to cast/convert it to integer before I need to sort it. What should be my linq statement?

Thanks in advance.

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

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

发布评论

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

评论(1

雨落□心尘 2024-10-01 05:48:31

执行如下操作:

Dim q = (from p in Data.Instance.Context.MyTable 
         select p).OrderBy(Function(p)Convert.ToInt32(p.Year))

上述查询是从 中提取的在这里

Do something like this:

Dim q = (from p in Data.Instance.Context.MyTable 
         select p).OrderBy(Function(p)Convert.ToInt32(p.Year))

The above query was extracted from here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文