Entity framework raw SQL Query

You have to capture the results into a class with matching property names, and (at least) a parameterless constructor:

class DbResult
{
    public int ID { get; set; }
    public string NAME { get; set; }
    public string DB_FIELD { get; set; }
}

var result = _dbContext.Database.SqlQuery<DbResult>(
                 "select ID, NAME, DB_FIELD from eis_hierarchy");

Leave a Comment