title: Entity Framework query similar to raw SQL query with order by date where null comes last
body: <p>l have a query</p>
  
  <pre><code>SELECT *
    FROM [ExcelDumps].[dbo].[ProductPrice] As p
    Where  
     ( 
      p.[EndDate] &gt;= '2018-12-18' 
      OR
      p.[EndDate] is null 
     ) 
     order by case when p.[EndDate] is null then 2 else 1 end, p.[EndDate] asc
  </code></pre>
  
  <p>what am trying to achieve is it possible to achieve the same results using Entity Framework where priority is lastly given to p.[EndDate]</p>
  
  <p>the desired output is as follows :</p>
  
  <p>what l have done </p>
  
  <pre><code> using (var cod = new ExcelDumpsEntities1())
              {
                  var list = cod.ProductPrices.Where(c =&gt; c.EndDate &gt;= c.EndDate || c.EndDate == null)
                                              .OrderBy(c =&gt; c.EndDate)
                                              .FirstOrDefault();
  
                  var sqlQuery = @"SELECT Top 1 *
                                    FROM [ExcelDumps].[dbo].[ProductPrice] As p
                                    Where  
                                     ( 
                                      p.[EndDate] &gt;= '2018-12-18' 
                                      OR
                                      p.[EndDate] is null 
                                     ) 
                                     order by case when p.[EndDate] is null then 2 else 1 end, p.[EndDate]  asc ";
                  var sqlRaw = cod.ProductPrices.SqlQuery(sqlQuery) 
                                              .FirstOrDefault();
              }
              Console.ReadLine();
  </code></pre>
  
  <p>I don't want to use SQL query or stored procedure but must do it in like LINQ to entities</p>
  
  <p>this question is based on this question on dba <a href="https://dba.stackexchange.com/questions/226679/select-within-or-closest-to-date-range-mssql/226695#226695">sql query here</a></p>
  
  <p>How can l do that in Entity Framework</p>