Artavazd
Artavazd

Reputation: 175

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!

Upvotes: 0

Views: 110

Answers (1)

Salah Akbari
Salah Akbari

Reputation: 39946

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()

Upvotes: 1

Related Questions