2012-11-15 45 views
0

我已經在我的項目中實現(或「借用」了Web!)通用存儲庫,並且現在仍然停留在如何通過此存儲庫訪問某些記錄。從通用存儲庫返回查詢行

的樣本數據:

ID | Policy ID  | History ID | Policy name 
1 | 1   | 0   | Test 
2 | 1   | 1   | Test 
3 | 2   | 0   | Test1 
4 | 2   | 1   | Test1 

我需要的是具有最大歷史記錄ID的記錄,所以策略ID 1和2將推出歷史ID 2(編號的2和4)。

我的通用存儲庫的代碼如下:

public virtual IEnumerable<TEntity> Get(
      Expression<Func<TEntity, bool>> filter = null, 
      Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, 
      params Expression<Func<TEntity, object>>[] includeProperties) 
     { 
      IQueryable<TEntity> query = dbSet; 

      if (filter != null) 
      { 
       query = query.Where(filter); 
      } 

      foreach (var includeProperty in includeProperties) 
      { 
       query = query.Include(includeProperty); 
      } 

      if (orderBy != null) 
      { 
       return orderBy(query).ToList(); 
      } 
      else 
      { 
       return query.ToList(); 
      } 
     } 

現在,我知道我應該使用這一功能的濾波器參數,而是如何在我的情況下,它甚至有可能?我想我必須使用分組方法。

我的調用代碼是(如果有幫助的話):提前

var policies = _policy.Get(); 

謝謝!

回答

0

我想你需要知道的泛型類型,然後才能做任何特定的linq東西像分組。例如,如果您不知道該類型,則無法指定要對其進行分組的任何屬性。