Search code examples
subsonicsubsonic3

Subsonic - My base class to accommodate different model classes and repository instances


I want to have a baseclass that will assign a DataGridView's datasource property.

I am using the ActiveRecord approach so all my code generated classes are of IActiveRecord.

IRepository needs my class to instantiate it.

I cannot seem to get this to work

What I want to do is something like this..

IActiveRecord GridObject;

public void SetupGrid()
{
db = new MyDB();
repo = new Repo<GridObject>(db);
DataGridView.DataSource = repo.GetAll();
}

This does not compile.

Any tips?


Solution

  • This seems to compile:

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