title: Filter dataset in repository design pattern C#
body: <p>I have a given below query, which is perfect</p>
  
  <pre><code>SELECT
      MAX(WarehouseId)       AS WareHouseId, 
      MAX(CompanyId)         AS CompanyId, 
      MAX(ProductId)         AS ProductId,
      SUM(AvailableQuantity) AS AvailableQuantity,
      PurchaseItemPrice 
  FROM
      PurchaseItem 
  WHERE
      CompanyId = 1 
  GROUP BY
      PurchaseItemPrice
  ORDER BY
      MAX(ProductId) ASC
  </code></pre>
  
  <p>Which I needs to convert into given below format instead of linq. I really don't know what is the name of given below format. Please also tell me what we can call this format and if this is not a good approach to get data please suggest something better because I'm new to repository design pattern.</p>
  
  <pre><code>unitOfWork.PurchaseItemRepository.DataSet
      .Where( x =&gt; x.CompanyId == id )
      .ToList()
      .GroupBy( x =&gt; x.PurchaseItemPrice )
      .Select( x =&gt;
          x.Max( y =&gt; new
          {
              y.WarehouseId,
              y.CompanyId,
              y.ProductId,
              y.AvailableQuantity
          } )
      );
  
  public IRepository&lt;PurchaseItem&gt; PurchaseItemRepository
  {
      get
      {
          if (_PurchaseItemRepository == null)
          {
              dbContext.Configuration.ProxyCreationEnabled = false;
              _PurchaseItemRepository = new Repository&lt;PurchaseItem&gt;(dbContext);
          }
          return _PurchaseItemRepository;
      }
  }
  </code></pre>
  
  <p>And <strong>ProductItem is an Entity</strong></p>
  
  <p>Moreover, when I executed above code, It will display given below error.</p>
  
  <blockquote>
    <p>An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code. Additional information: At least one object must implement IComparable.</p>
  </blockquote>