I have a working sql query that I have been trying to convert to linq for the past couple of days. I have read several posts both here and on various site, but have not been successful in any of my attempts to convert this to a working linq query.
The parts that I am specifically having problems with deal with the math (adding individual scores to get the total_score value) and getting the values from the Schools table so I can pass them to my view.
Here is the sql query:
SELECT bowler_name, school_name, bowler_gm1, bowler_gm2, bowler_gm3, bowler_gm4, bowler_gm5, bowler_gm6, (ISNULL([bowler_gm1],0)+ISNULL([bowler_gm2],0)+ISNULL([bowler_gm3],0)+ISNULL([bowler_gm4],0)+ISNULL([bowler_gm5],0)+ISNULL([bowler_gm6],0)) AS total_score
FROM Bowlers
JOIN Schools ON Schools.school_id = Bowlers.school_id
ORDER BY total_score DESC;
Here is as far as I get with the linq query before things start breaking:
from s in db.Schools
join b in db.Bowlers on s.school_id equals b.school_id
select b;
Any help would be much appreciated. Thanks!
Something like this should help you on your way.
Note it would be much easier to handle nulls if you were to create a BowlerGame table with
GameID as PK, BowlerID as FK to bowler, GameNumber as game number and finally Score as that game’s score