cesarlinux
cesarlinux

Reputation: 37

How to obtain primary key from table in Subsonic 2.0

I've a method like below, given a table name and where condition (column and value) the idea is obtain the primary key value for this condition

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

My Table "t" is created without errors, but t.PrimaryKey and other members are always null, how can I resolve this using subsonic 2.x? Thanks!

Upvotes: 0

Views: 106

Answers (1)

Mike Walsh
Mike Walsh

Reputation: 198

Try this:

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

Where the provider name is in your subsonic web config section.

Upvotes: 1

Related Questions