Casting to varchar using Subsonic 2.2

91 Views Asked by At

How can I reproduce

SELECT CAST(ID AS varchar(20)) AS IdAsString
FROM Table

Using Subsonic 2.2?

2

There are 2 best solutions below

0
Ben McIntyre On

Once you've generated classes from the database, something like this:

TableCollection tc = new TableCollection ();
TableCollection.Load();
string s = "";
foreach (Table t in tc) {
    s += " " + t.ID.ToString();
}

I'm assuming you want the whole table, otherwise you'd probably have the ID to start with. You can also use

TableCollection.WHERE("OtherColumn", 23).Load();

to retrict the table records returned.

0
marapet On
DAL.DB.Select(
    string.Format("CAST({0} AS varchar(20)) AS IdAsString", DAL.Table.Columns.ID)
    )
.From<DAL.Table>()
...