Repository navigation
Mise Aliases
An alias gives a mapped table another SQL name. Use it to distinguish tables in joins or to reference the same table more than once.
Add repeatable [Alias] attributes to the table:
// CampusTbl.cs
[PostgreSqlTable("campuses")]
[Alias("Campus")]
[Alias("HomeCampus")]
public static partial class CampusTbl
{
[Column("campus_id")]
[PrimaryKey]
private static int CampusId { get; }
[Column("name")]
private static string Name => string.Empty;
}The generator creates nested classes named Campus and HomeCampus. Each exposes its own Table and column constants. CampusTbl.Campus.Table includes AS "Campus", and CampusTbl.Campus.NameCol refers to "Campus"."name".
var query = new PostgreSqlQueryBuilder()
.Select($"{CampusTbl.Campus.CampusIdCol:raw}")
.Select($"{CampusTbl.Campus.NameCol:raw}")
.From($"{CampusTbl.Campus.Table:raw}");Once the source is aliased, use its alias-qualified columns throughout that query. The unaliased CampusTbl.NameCol refers to the original table name, which no longer names that source in the SQL statement.
Aliases change how SQL references a table. They do not change result column names. If two selected tables have the same column name, give those projection terms distinct SQL aliases and map the row to those names. See Result rows.
When a relationship target declares aliases, Mise generates a join fragment for each target alias. A relationship named CampusIdJoin gains CampusIdJoinCampus and CampusIdJoinHomeCampus.
Source aliases also expose relationship fragments that use the aliased source in the ON predicate. For example, CourseTbl.Course.CampusIdJoinCampus joins from Course to Campus.
See Relationships for generated fragment names and Joins for complete projections.
Alias names must be nonempty and unique under the engine's identifier comparison rules. Avoid names that collide with generated table, column, or join members. See Diagnostics for build errors.
- Home
- Getting started
-
Package guides
- Partie
- Expo
-
Mise
- Database setup
- Table mappings
- Aliases
- Relationships
- Result rows
- SQL interpolation
- Queries
- Filtering
- Joins
- Aggregation
- Paging and ordering
- Subqueries
- Set operations
- Common table expressions
- Readers
- Streaming
- Writers
- Inserts
- Updates
- Deletes
- Returned rows
- Custom SQL and procedures
- Transactions
- Resource lifetimes
- Database dialects
- Diagnostics
- Integrations
- Recipes
- Reference
- Troubleshooting
- Development