[Solved] How to read result from raw SQL command


Nobody found the answer. But it is easier to downvote than solving code issues !
So, here is the answer, i hope it will help other guys who encounter the same problem.
1 / Assuming you build a query which creates a table with custom columns named “Name, State, Nb, Avg, Min, Max :

string query2 = "SELECT s.Name, t.State, Count(*) [Nb], 
AVG(t.Duration) [Avg], 
MIN(t.Duration) [Min], 
MAX(t.Duration) [Max] from ...";

2 / you have to create a class for the mapping from database to object :

public class stats
{
    public String Name { get; set; }
    public Int32 State { get; set; }
    public Int32 Nb { get; set; }
    public Int32 Avg { get; set; }
    public Int32 Min { get; set; }
    public Int32 Max { get; set; }
}

3 / then you execute the query :

IEnumerable<stats> data = db.Database.SqlQuery<stats>(query2);

db is the class which extends DbContext

solved How to read result from raw SQL command