作者areyo (沒有名字的怪物)
看板C_Sharp
標題[問題] 關於Lambda語法
時間Tue Aug 23 16:04:10 2016
小弟想請教個問題
我用mssql當作資料庫,透過EF去取資料,想要作排序的動作 (依日期)
code如下
var t2 = (from t in _dbContext.prediction_table
where t.final_score != null
&& t.final_score != "cancel"
&& t.final_score != "postponed"
orderby t.gamedate_judge descending
select t.gamedate_judge).Distinct();
(gamedate_judgu型態是DateTime),理論上這樣應該是取出排序過的值
可我將其轉存到DateTime[] dt = t2.ToArray();
卻發現內容不是按順序排,出現如下結果
2016/6/6 上午12:00:00
2016/7/6 上午12:00:00
2016/7/22 上午12:00:00
2016/5/31 上午12:00:00
2016/7/30 上午12:00:00
是我弄錯語法嗎??
可否告知方向,謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.121.218.23
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1471939454.A.0CA.html
→ ssccg: Distinct會回沒有排序的結果,要把orderby放在後面 08/23 16:08
→ areyo: ssccg謝謝您的指導。 08/23 19:04