gehgassi_backend/gehGassi.Persistence/Migrations/20220820154125_tv_NewsWithNames.cs

30 lines
1.3 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
using System;
#nullable disable
namespace gehGassi.Persistence.Migrations
{
public partial class tv_NewsWithNames : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
var viewName = "tv_NewsWithNames";
var sql = @"CREATE FUNCTION tv_NewsWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
SELECT dbo.News.*,
NC.Name AS CategoryName
FROM dbo.News
LEFT JOIN dbo.tv_NewsCategoryWithNames(@language, @fallback) NC ON dbo.News.CategoryId = NC.Id";
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
migrationBuilder.Sql($"{sql} {Environment.NewLine} GO");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
var viewName = "tv_NewsWithNames";
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
}
}
}