简体   繁体   中英

Translate an SQL query into LINQ

I'm struggling to translate the following SQL query into LINQ. The outcome column is in type ( varchar ) in the database and I want to cast that into float / double with LINQ.

SELECT TOP 10 CAST(Outcome AS float) AS Max_Outcomes
FROM GameState
where GameId = 1000
ORDER BY Max_Outcomes DESC

Much appreciated!

Something like this:

var result = _yourDbContext.GameState
             .Where(c => c.GameId == 1000).AsEnumerable()
             .Select(c => new { Max_Outcomes = (float)c.Outcome })
             .OrderByDescending(c=> c.Max_Outcomes).Take(10).Tolist()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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