Search code examples
subsonicsubsonic2.2

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!


Solution

  • Try this:

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

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