Skip to content

Mise Aliases

SteffenBlake edited this page Sep 28, 2026 · 1 revision

Table 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.

Declare aliases

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".

Use matching references

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.

Relationship aliases

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.

Naming checks

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.

Clone this wiki locally