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 就可以在一个函数中处理保存?

到目前为止我的方法:

    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; 
    }

到目前为止一切顺利,但现在我需要将 datacontext 转换为指定的上下文,以访问 Entities 属性。

到目前为止,您认为这可能吗?还是有更简单的解决方案?

谢谢,大家晚上好。

马蒂亚斯·穆勒

4

0 回答 0