diff --git a/Apollon.EntityFramework/Migrations/20220820005557_initial.Designer.cs b/Apollon.EntityFramework/Migrations/20220820005557_initial.Designer.cs new file mode 100644 index 0000000..191c8b7 --- /dev/null +++ b/Apollon.EntityFramework/Migrations/20220820005557_initial.Designer.cs @@ -0,0 +1,61 @@ +// +using System; +using Apollon.EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Apollon.EntityFramework.Migrations +{ + [DbContext(typeof(TournamentsDbContext))] + [Migration("20220820005557_initial")] + partial class initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("Apollon.EntityFramework.DTOs.TournamentDto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Competition") + .HasColumnType("nvarchar(max)"); + + b.Property("EndDate") + .HasColumnType("datetime2"); + + b.Property("Location") + .HasColumnType("nvarchar(max)"); + + b.Property("Organisation") + .HasColumnType("nvarchar(max)"); + + b.Property("Rounds") + .HasColumnType("int"); + + b.Property("StartDate") + .HasColumnType("datetime2"); + + b.Property("TournamentName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Tournaments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Apollon.EntityFramework/Migrations/20220820005557_initial.cs b/Apollon.EntityFramework/Migrations/20220820005557_initial.cs new file mode 100644 index 0000000..240b2fd --- /dev/null +++ b/Apollon.EntityFramework/Migrations/20220820005557_initial.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Apollon.EntityFramework.Migrations +{ + public partial class initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Tournaments", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Organisation = table.Column(type: "nvarchar(max)", nullable: true), + TournamentName = table.Column(type: "nvarchar(max)", nullable: true), + Competition = table.Column(type: "nvarchar(max)", nullable: true), + StartDate = table.Column(type: "datetime2", nullable: false), + EndDate = table.Column(type: "datetime2", nullable: false), + Location = table.Column(type: "nvarchar(max)", nullable: true), + Rounds = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tournaments", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Tournaments"); + } + } +} diff --git a/Apollon.EntityFramework/Migrations/TournamentsDbContextModelSnapshot.cs b/Apollon.EntityFramework/Migrations/TournamentsDbContextModelSnapshot.cs new file mode 100644 index 0000000..2207312 --- /dev/null +++ b/Apollon.EntityFramework/Migrations/TournamentsDbContextModelSnapshot.cs @@ -0,0 +1,59 @@ +// +using System; +using Apollon.EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Apollon.EntityFramework.Migrations +{ + [DbContext(typeof(TournamentsDbContext))] + partial class TournamentsDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("Apollon.EntityFramework.DTOs.TournamentDto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Competition") + .HasColumnType("nvarchar(max)"); + + b.Property("EndDate") + .HasColumnType("datetime2"); + + b.Property("Location") + .HasColumnType("nvarchar(max)"); + + b.Property("Organisation") + .HasColumnType("nvarchar(max)"); + + b.Property("Rounds") + .HasColumnType("int"); + + b.Property("StartDate") + .HasColumnType("datetime2"); + + b.Property("TournamentName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Tournaments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory - Copy.cs b/Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory - Copy.cs deleted file mode 100644 index ae4dbb2..0000000 --- a/Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory - Copy.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Apollon.EntityFramework -{ - public class TournamentsDbContextFactory - { - private readonly DbContextOptions _options; - - public TournamentsDbContextFactory(DbContextOptions options) - { - _options = options; - } - - public TournamentsDbContext Create() - { - return new TournamentsDbContext(_options); - } - } -} diff --git a/Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory.cs b/Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory.cs new file mode 100644 index 0000000..ca0f1ac --- /dev/null +++ b/Apollon.EntityFramework/TournamentsDesignTimeDbContextFactory.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Apollon.EntityFramework +{ + public class TournamentsDesignTimeDbContextFactory : IDesignTimeDbContextFactory + { + + public TournamentsDbContext CreateDbContext(string[] args = null) + { + return new TournamentsDbContext(new DbContextOptionsBuilder().UseSqlServer("Data Source=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true").Options); + } + } +} diff --git a/Apollon.WPF/App.xaml.cs b/Apollon.WPF/App.xaml.cs index 3a3d36e..e2b5ffa 100644 --- a/Apollon.WPF/App.xaml.cs +++ b/Apollon.WPF/App.xaml.cs @@ -34,7 +34,7 @@ namespace Apollon.WPF public App() { - string connectionString = "Data Source=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true"; + string connectionString = "Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true"; _modalNavigationStore = new ModalNavigationStore(); _tournamentsDbContextFactory = new TournamentsDbContextFactory( @@ -48,6 +48,11 @@ namespace Apollon.WPF } protected override void OnStartup(StartupEventArgs e) { + using(TournamentsDbContext context = _tournamentsDbContextFactory.Create()) + { + context.Database.Migrate(); + } + OverviewViewModel overviewViewModel = new OverviewViewModel( _tournamentStore, _selectedTournamentStore,