Search code examples
subsonicsubsonic3

Subsonic - Return only certain columns/properties for display


I have a baseclass that handles returning data from the relevant class/table.

I want to have some way of specifying the columns to display. Maybe have a public columns List that gets assigned with all column we want to display?

This is what I have but its not right.

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 };

        }

Solution

  • This seems to do it, however unsure if its best practice:

     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;
    
    
    
            }