title: How to write complex SQL Query using Entity Framework?
body: <p>I have to write a complex SQL Query using Entity Framework , but I can not figure out how to combine them , but at the same time to have a  code with an  optimal execution.</p>
  
  <p>Here is my SQL Query:</p>
  
  <pre><code>Select DATEPART(HOUR,Datetime),AVG(temperature1),AVG(temperature2),AVG(humidity1), 
  from Table ,
  where Day(Datetime)=@param, 
  group by DATEPART(HOUR,Datetime),
  order by DATEPART(HOUR,Datetime);
  </code></pre>
  
  <p>And here is what I've tried using Entity Framework :</p>
  
  <pre><code>  List&lt;Greenhouse&gt; greenhouse = context.Greenhouses
    .Where(x =&gt; x.Datetime.Day == DtFrom.Day &amp;&amp; x.Datetime.Month == DtFrom.Month &amp;&amp; x.Datetime.Year == DtFrom.Year).ToList();
    //.GroupBy(x =&gt; x.Datetime.Hour).ToList;
  </code></pre>
  
  <p>Can anyone help me with some ideas?Thanks.</p>