Is there a way to rename fields when executing a select statement in SubSonic? I am using the ExecuteTypedList<MyClass> method to fill my List<MyClass> object but the properties of MyClass are not all the same as the column names from the DB table. In SQL I can do select col1 as 'FirstColumn', col2 as 'SecondColumn' from MyTable, is there a way to do something similar in SubSonic?
+1
A:
I believe Alias's are only available for aggregate columns. You could just add properties of the same names as your columns to your class or a partial and map them to the properties you do use ala calculated field:
public class Songs
{
private string _songTitle;
public string SongTitle {
get { return _songTitle; }
set { _songTitle = value; }
}
public string SongName {
get { return _songTitle; }
set { _songTitle = value; }
}
}
Zapatta
2009-05-07 14:35:59
+1
A:
I had the same need the other day, and added the functionality to my local copy of SubSonic. I've just submitted it a patch for it attached to this issue. Applying the patch will let you write a query like
new Select(Table1.IdColumn.AliasAs("table1ID"),
Table2.IdColumn.AliasAs("table2ID"))
.From(Table1.Schema)
.InnerJoin(Table2.Table1IdColumn, Table1.IDColumn);
ranomore
2009-05-07 20:04:29