I'm having a tables Namely StudentInfo
and ScoreInfo
Table: DbSet<StudentInfo>
ID Name
_____________________
1 Ram
2 Kumar
Table: DbSet<ScoreInfo>
Id StudentId Subject Score
_____________________________________
1 1 GK 90
2 1 PHY 97
3 1 CHE 89
4 1 BIO 93
5 1 TAM 100
6 1 ENG 95
7 2 GK 85
8 2 PHY 76
9 2 CHE 63
10 2 BIO 79
11 2 TAM 61
12 2 ENG 60
The Linq to SQL Query (IQueryable
)
using(var db = new DBContext()) {
IQueryable<ScoreInfo> resultQuery = db.ScoreInfos.OrderBy(????)
.Take(5)
}
The Order By Logic is
((m.Subject == "GK") || (m.Subject == "PHY") (m.Subject == "CHE") || (m.Subject == "BIO"))
? "Science"
: "Arts"
The LINQ to SQL return result should be (Expected)
Id StudentId Subject Score
_____________________________________
5 1 TAM 100
6 1 ENG 95
11 2 TAM 61
12 2 ENG 60
1 1 GK 90
The variable sortColumn
is a assumption column based on the Sort Logic which was specified in above. Kindly assist me how to write the Expression<Func<ScoreInfo,object>>
i.e., OrderBy(Expression<Func<ScoreInfo,object>>)
?