schotime/NPoco — pull request #80 by techniq (2014-02-14 05:02:25+00:00)
Title: Add column aliasing support

Column aliasing is needed for Oracle paging ([pre 12c](http://www.oracle-base.com/articles/12c/row-limiting-clause-for-top-n-queries-12cr1.php) which finally offers sane syntax) when joining tables and returning columns from those tables with conflicting names. Without aliasing you'll receive the usual `ambiguous column name` error on the wildcard select.

Here's is a simplified version from one of my projects where I join `FeedbackType` and `FeedbackStatus` to the `Feedback` table and return only the first page. I built the `sqlPage` query using `SqlBuilder` and `Database.BuildPageQueries(...)`. I plan to simplify this by improving `Database.SkipTake(...)` soon.

*Query call*
```
var data = Database.Query(sqlPage);
```

*Generated query*
```sql
SELECT * FROM (
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL from dual)) peta_rn,
peta_base.* FROM (
SELECT
f.id,
f.title,
ft.id as type_id,
ft.name as type_name,
fs.id as status_id,
fs.name as status_name
FROM Feedback f
INNER JOIN feedback_type ft ON ft.Id = f.feedback_type_id
INNER JOIN feedback_status fs ON fs.Id = f.feedback_status_id) peta_base
) peta_paged
WHERE peta_rn>0 AND peta_rn<=10
ORDER BY peta_rn
```

*Pocos*
```c#
public class Feedback
{
public int Id { get; set; }
public string Title { get; set; }

public FeedbackType Type { get; set; }
public FeedbackStatus Status { get; set; }
}

public class FeedbackType
{
[Alias("type_id")]
public int Id { get; set; }
[Alias("type_name")]
public string Name { get; set; }
}

public class FeedbackStatus
{
[Alias("status_id")]
public int Id { get; set; }
[Alias("status_name")]
public string Name { get; set; }
}
```

I'm also trying to come up with a way to auto-prefix-alias all columns in a Poco, either with table attribute such as `[ColumnPrefixAlias("type_")]` or during query time.