I have this extension method.

```
    public static List<Framework.Model> FetchAll(this Framework.Model model)
    {
        List<Framework.Model> models = new List<Framework.Model>();

        StringBuilder Fields = new StringBuilder();

        var properties = GetProperties(model);

        foreach (var p in properties)
        {
            if (!p.Name.Equals("Table"))

                Fields.Append(p.Name + ",");
        }

        Fields.Length--;

        System.Data.DataTable data = (System.Data.DataTable)engine.RunDataTable("select " + Fields.ToString() + " from " + model.Table + ";").Data;

        foreach (System.Data.DataRow rw in data.Rows)
        {
            foreach (System.Data.DataColumn col in data.Columns)
            {
                foreach (var p in properties)
                {
                    if (col.ColumnName.Equals(p.Name))
                    {
                        if (p.PropertyType == typeof(DateTime?))
                        {
                            p.SetValue(model, DateTime.Parse(rw[col.ColumnName].ToString()));
                        }
                        else
                        {
                            p.SetValue(model, Convert.ChangeType(rw[col.ColumnName], p.PropertyType));

                        }
                    }

                }

            }

            models.Add(model);

        }

        return models;

    }

```

and I have this base class.

```
public interface Model
{
    string Table { get; set; }
}

```

and I also have this sub class.

```
 public class Department : Framework.Model
{
    public Department()
    {
        this.Table = "departments";
    }

    public int Dbid { get; set; }
    public string Code { get; set; }
    public DateTime? created_at { get; set; }
    public DateTime? updated_at { get; set; }

    public string Table
    {
        get; set;
    }
}

```

i now tried to use the extension method above.

```
List<Model.Department> depts = new List<Model.Department>();
depts = new Model.Department().FetchAll();

```

but its a compiler error since it cannot cast the base class to sub class.
my question only is how to return a sub class because all i want is when i call the extension method it will return all the data on the database on that certain table which is my sub class so i want to fetch a list of sub classes.

BTW the extension method is I want that to be flexible that can accept different sub classes that's why i build it that way.