2010-02-01 76 views
1

我有一個處理從相關類/表返回數據的基類。Subsonic - 僅返回顯示的某些列/屬性

我想有一些方法來指定要顯示的列。也許有一個公開的列列表,它被分配給我們想要顯示的所有列?

這是我的,但它不正確。

public void SetupGrid<T>() where T : class, new() 
     { 
      var db = new MyApp.MyDB(); 
      IRepository<T> repo = new SubSonicRepository<T>(db); 
      var s = repo.GetAll(); 


      var x = from c in s select new { c.Columns //that match columns I specify }; 

     } 

回答

0

這似乎做它,如果它的最佳實踐然而不確定:

public virtual void SetupGrid<T>() where T : class, new() 
     { 
      MyApp.MyDBdb = new MyApp.MyDB(); 
      IRepository<T> repo = new SubSonicRepository<T>(db); 
      ITable table = repo.GetTable(); 


      List<string> list = new List<string>(); 
      list.Add("CreatedOn"); 
      list.Add("PageID"); 
      list.Add("CreatedBy"); 

      var s = db.SelectColumns(list.ToArray()). 
        From(table.Name). 
        OrderAsc(table.Descriptor.Name).ExecuteReader(); 



      bindingSource1.DataSource = s; 



     }