久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Orderby() 沒有正確排序數字 c#

Orderby() not ordering numbers correctly c#(Orderby() 沒有正確排序數字 c#)
本文介紹了Orderby() 沒有正確排序數字 c#的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在為我的公司編寫一個應用程序,目前正在研究搜索功能.當用戶搜索一個項目時,我想顯示最高版本(存儲在數據庫中).

I am writing an app for my company and am currently working on the search functionality. When a user searches for an item, I want to display the highest version (which is stored in a database).

問題是,版本存儲為字符串而不是整數,當我對結果執行 OrderBy(q=>q.Version) 時,它們會像

The problem is, the version is stored as a string instead of int, and when I do an OrderBy(q=>q.Version) on the results, they are returned like

1
10
11
2
3
...

顯然 2 在 10 之前.

Obviously 2 comes before 10.

有沒有辦法讓我將版本轉換為整數,或者是否有一個簡單的 IComparer?到目前為止,我找不到任何實質性的東西.

Is there a way for me to cast the version as an integer or is there a simple IComparer out there? I couldn't find anything substantial thus far.

我嘗試這樣做:

var items = (from r in results
             select r).OrderBy(q => Int32.Parse(q.Version));

這可以編譯但不起作用.

This compiles but doesn't work.

推薦答案

LinqToSql 轉換器不支持 Int32.Parse.支持 Convert.ToInt32.

Int32.Parse is not supported by the LinqToSql translator. Convert.ToInt32 is supported.

http://msdn.microsoft.com/en-us/library/sf1aw27b.aspx

http://msdn.microsoft.com/en-us/library/bb882655.aspx

這篇關于Orderby() 沒有正確排序數字 c#的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 欧美日韩三级在线观看 | 91www在线观看 | 日本字幕在线观看 | 国产精品a久久久久 | 日韩久久网 | 黄色网址在线免费观看 | 国产精品久久久久久久久久免费 | 日韩成人高清在线 | 日韩欧美在线视频 | 中文字幕在线观看一区 | www.成人.com| 四色成人av永久网址 | 久久亚洲精品国产精品紫薇 | 99精品国产成人一区二区 | 国产一区二区三区四区五区加勒比 | 日韩一区二区免费视频 | 日本精品在线观看 | 99精品在线观看 | 国产精品一区二区视频 | 日本精品一区二区三区在线观看视频 | 久久国产精品免费 | 欧美色a v| 免费毛片网站 | 欧美456| 国产午夜久久 | 久久中文字幕一区 | 日韩中文字幕在线不卡 | 日本h片在线观看 | 国产精品久久久久久久午夜片 | 亚洲精品91 | 成人性生交大片免费看r链接 | 99视频在线免费观看 | 黄色片大全在线观看 | 手机看片1 | 国产激情一区二区三区 | 97精品超碰一区二区三区 | 亚洲风情在线观看 | 午夜精品一区二区三区在线视频 | 亚洲精品久久久一区二区三区 | 久久久久国产一区二区三区四区 | 伊人啪啪网 |