I have this SQL query
select o.id, o.name , k.image
from dbo.Office as o
left join dbo.Rate as r on o.id = r.officeid
left join dbo.Splash as k on k.officeid = o.id
group by o.id, o.name, k.image
order by avg(r.value) desc
now, I would like to convert it to Entity framework syntax.
How to achieve this?
Answered by:- neena
You can try this command using Entity framework (.edmx model), i suppose you have created .edmx and mapped your database with the application(this is half solution)
using (var ctx = new EdmxContext())
{
var query = ctx.Office
.Include(a=>a.Rate)// Your Rate table id is linked with Office table using reltionship
.Include(a=>a.Splash) // Your Rate table id is linked with Office table using reltionship
.GroupBy(a=>a.Office.id).OrderByDescending(a=>a.Value).ToList();
}
Above is half solution, to properly check your page table details, please provide database relationship image, with example data, i test it here and try to give bettter reply
Or check these links for taking out Average
Answered by:- pika
You can run your query using Entity framework also, with the help of .SQLQuery() method, something like this
var query = "SELECT * FROM table_name";
var queryResult=Context.Table_Name.SqlQuery(query).ToList();
it may help you.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly