Linq query to get data from Database using group by clause <p>I am developing MVC4 application. I ended up with one complex scenario. I have following table in sql.</p> <pre><code>upld_Id Label Value Commited 1000 DocNumber 123 0 1000 ExpiryDate 01/01/2016 0 1000 Docnumber 456 1 1000 ExpiryDate 01/01/2018 1 </code></pre> <p>I am supposed to get output in the below format.</p> <pre><code>upld_Id Label OldValue NewValue 1000 Docnumber 123 456 1000 ExpiryDate 01/01/2016 01/01/2018 </code></pre> <p>I tried as below.</p> <pre><code>var logDetails = (from c in db.logTable join tbl in db.MetaTable on c.id equals tbl.id //GroupBy where (c.commited==false || c.commited==true) select new ClassName { //Get Values }).toList(); </code></pre> <p>This is what i tried in LINQ. I am not sure how to apply LINQ here</p> <pre><code>var logDetails = (from c in db.ts_upldlog_content join tbl in db.ts_upld_doc on c.upld_docid equals tbl.upld_docid join doc in db.tm_doc_type on tbl.upld_doctypeid equals doc.doc_typeid where c.upld_docid==data group c by c.upld_contentlabel into grouping select new logdetails { updatedOn=c.updatedOn //Here Error contentLabel=grouping.Key, oldValue = grouping.FirstOrDefault(x =&gt; x.commited ==false).upld_contentvalue, newValue = grouping.FirstOrDefault(x =&gt; x.commited == true).upld_contentvalue, }).ToList(); </code></pre> <p>Can someone tell me is this possible in LINQ? Thanks</p>