Rename fields in SubSonic selection instructions
Is there a way to rename fields when executing select statement in SubSonic? I am using the ExecuteTypedList <MyClass> method to populate my <MyClass> list but the properties of MyClass do not match the column names from the DB table. In SQL, I can make select col1 as "FirstColumn", col2 as "SecondColumn" from MyTable, is there a way to do something like this in SubSonic?
I believe the alias is only available for aggregate columns. You can simply add properties with the same names as your columns to your class or partial and map them to the properties you use for the 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; }
}
}
a source to share
I had the same need the other day and added functionality to my local copy of SubSonic. I just sent him a patch for him attached to this issue . Applying a patch will allow you to write a request like
new Select(Table1.IdColumn.AliasAs("table1ID"),
Table2.IdColumn.AliasAs("table2ID"))
.From(Table1.Schema)
.InnerJoin(Table2.Table1IdColumn, Table1.IDColumn);
a source to share