title: Generating ROW_NUMBER() with partition in EF
body: <p>I have a query in <code>T-SQL</code> which contains partition by clause and based on the ROWNumber generated i want to pull on 2 things:</p>
  <p>
  <ol><li>Results having more than one record (probably taking the latest from the parition clause)</li>
  <li>Pulling first record from the above point (point #1).</li></ol>
  </p>
  <p>Here's my T-SQL query which i want to convert into EF:</p>
  <pre><code>select * from 
  (
  select StudentId, ProgramId, StudentProgramTaggingId, 
         ROW_NUMBER() OVER(Partition By StudentId, ProgramId order by StudentProgramTaggingId) as RowNum 
  from MahadStudentProgramHistory
  group by StudentId, ProgramId, StudentProgramTaggingId
  )a where a.RowNum &gt; 1
  </code></pre>
  <p>Here's what i tried in EF to get the desired results:</p>
  <pre><code>var studentPrograms = db.StudentProgramHistories;
                  var groupByStudents = studentPrograms
                      .GroupBy(x =&gt; new
                      {
                          x.StudentId,
                          x.ProgramId
                      })
                      .Select(x =&gt; x.Count() &gt; 1)
                      .Select(x =&gt; x).ToList();
  </code></pre>
  <p>The above EF code pulls all the records skipping duplicates, however i want the opposite, i want to get the first record from the duplicates and ignore all orders which are singles.</p>