Entity-Framework-DBZ/EntityFrameworkCore.Data/Migrations/20250407174459_AddTeamLeaguesAndCoachesView.cs
2025-04-07 20:10:53 +02:00

33 lines
1022 B
C#

using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkCore.Data.Migrations
{
/// <inheritdoc />
public partial class AddTeamLeaguesAndCoachesView : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// I added this SQL manually, by first creating an empty migration.
// A view is a read-only representation of a data set.
migrationBuilder.Sql(@"
CREATE VIEW vw_TeamsAndLeagues
AS
SELECT t.name, l.Name AS LeagueName
FROM Teams AS t
LEFT JOIN Leagues AS l ON t.LeagueId = l.Id
");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
// Don't forget this part as well, for each manually added SQL statement.
migrationBuilder.Sql(@"DROP VIEW vw_TeamsAndLeagues");
}
}
}