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ました。

SQLEventUnitsTables 、SQLDisciplinesなどを動的に取得したいと思います。誰でも方法を知っていますか?前もって感謝します!

4

1 に答える 1

0

Microsoft Enterprise Library をご存知ですか? 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 に答える