如何从Subsonic 2.0中的表中获取主键

时间:2012-08-14 13:31:38

标签: subsonic subsonic2.2

我有一个类似下面的方法,给定一个表名,其中条件(列和值)的想法是获得此条件的主键值

    public static int getid(string table, string wherecolumn, string wherevalue) {
        SubSonic.TableSchema.Table t = new TableSchema.Table(table);
        SubSonic.Select s1 = new SubSonic.Select(t.PrimaryKey);
        s1.From(t);
        s1.Where(wherecolumn).IsEqualTo(wherevalue);
        return s1.ExecuteScalar<int>();
    }

我的表“t”创建没有错误,但t.PrimaryKey和其他成员始终为null,我如何使用亚音速2.x解决此问题? 谢谢!

1 个答案:

答案 0 :(得分:1)

试试这个:

var t = DataService.GetSchema(table, providername);

提供商名称在您的亚音速Web配置部分。