0

我想使用自己的函数来处理不同的数据库表。当我使用 SQLite 时,这些表是使用自定义类填充的。我试图以递归方式填充它们,所以我创建了这个结构和数组:

public class cCodesPair
{
    public string cCodeKey { get; set; }
    public Type CommonCodeClass { get; set; }

    public cCodesPair(string key, Type o)
    {
        this.cCodeKey = key;
        this.CommonCodeClass = o;
    }
}

    private cCodesPair[] codesPairs = new cCodesPair[] 
    {
        new cCodesPair("DESC_UNITS", typeof(SQLEventUnits)),
        new cCodesPair("DESC_DISCIPLINE", typeof(SQLDisciplines)),
        new cCodesPair("DESC_COUNTRY", typeof(SQLCountries)),
        new cCodesPair("DESC_VIDEOS", typeof(SQLVideos)),
        new cCodesPair("DESC_ATHLETES", typeof(SQLAthletes))
    };

创建这个的想法是遍历数组以创建查询表并为每个表填充字典。

试图做到这一点的功能是:

    public void Load<T>(T t, SQLiteConnection conn) where T : Type
    {
        try
        {
            var query = conn.Table<T>;

            //MORE CODE...

        } catch (Exception ex)
        {
            Debug.WriteLine("Exception")
        }
    }

遍历数组并调用Load函数的函数如下:

    private async Task fillDictionaries()
    {
        for (int i = 0; i < codesPairs.Length; i++)
        {
            MasterDescriptions m = new MasterDescriptions();
            Type t = codesPairs[i].CommonCodeClass;
            m.Load(t, conn);
        }
    }

但我知道查询的表是一个叫Type.

我想动态地获得 Tables SQLEventUnitsSQLDisciplines等。有谁知道怎么做?提前致谢!

4

1 回答 1

0

你知道微软企业库吗? https://msdn.microsoft.com/en-us/library/ff648951.aspx

正是你想要实现的。另一个参考: http: //www.codeproject.com/Tips/657233/Enterprise-Library-6-Sqlite-Logging-and-Exceptions

于 2015-11-16T19:15:33.757 回答