1

学習目的のためだけにアプリを作成しようとしています。オブジェクトを適切なコンテキストに動的に保存したいと思います。だから私の考えは次のようなものです:

プレーヤーの私のビジネスモデルは次のとおりです。

[Table]
public class PLAYER:ISiedlerEntity
{
    [Column(CanBeNull = false, IsPrimaryKey = true, DbType = "INT NOT NULL Identity", IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public long ID { get; set; }
    [Column]
    public string Name { get; set; }
    [Column]
    public int GamesPlayed { get; set; }
}

}

コンテキストは次のとおりです。

public class PLAYERS:DataContext
{
    private const string CONNECTION_STRING = "isostore:/tblPLAYERs.sdf";

    public Table<PLAYER> Entities;

    public PLAYERS()
        : base(CONNECTION_STRING)
    {
    }
} 

ISiedlerEntitiy を渡すだけで、1 つの関数で保存を処理できる可能性があると思いますか?

これまでの私のアプローチ:

    public static bool Save(ISiedlerEntity entity)
    {
        bool result = true;
        string dcName = entity.GetType().Name + "S";
        PropertyInfo pi = CurrentApp.GetType().GetProperty(dcName);
        DataContext dc = pi.GetValue(CurrentApp) as DataContext;

        foreach (var prop in dc.GetType().GetProperties())
        {
            if (prop.Name == "Entities")
            {
                var t = prop.GetValue(dc);

            }
        }


        return result; 
    }

ここまでは問題ありませんでしたが、Entity プロパティにアクセスするために、datacontext を指定されたコンテキストにキャストする必要があります。

これは今のところ可能だと思いますか?または、より簡単な解決策はありますか?

ありがとう、そして皆さん、こんばんは。

マティアス・ミュラー

4

0 に答える 0