Setup database configuration for storing information

This commit is contained in:
Ross Healy
2024-02-07 22:47:41 +00:00
parent 4981570d4e
commit c897f58128
8 changed files with 424 additions and 21 deletions

View File

@@ -7,7 +7,7 @@ namespace lottery_co_uk_scraper.data
{
public static void SaveModelToDatabase(LottoResult lottoResults)
{
using var dbContext = new LottoDbContext(new DbContextOptions<LottoDbContext>());
using var dbContext = new LotteryContext();
dbContext.Database.EnsureCreated();
dbContext.LottoResults.Add(lottoResults);

View File

@@ -1,20 +0,0 @@
using lottery_co_uk_scraper.core.Models;
using Microsoft.EntityFrameworkCore;
namespace lottery_co_uk_scraper.data
{
public class LottoDbContext(DbContextOptions<LottoDbContext> options) : DbContext(options)
{
public DbSet<LottoResult> LottoResults { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LottoResult>().HasKey(e => e.Id);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=Lotto;Trusted_Connection=True;");
}
}
}

View File

@@ -0,0 +1,23 @@
using lottery_co_uk_scraper.core.Models;
using Microsoft.EntityFrameworkCore;
namespace lottery_co_uk_scraper.data
{
public class LotteryContext : DbContext
{
public DbSet<LottoResult> LottoResults { get; set; }
public LotteryContext()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("");
}
}
}
}

View File

@@ -0,0 +1,161 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using lottery_co_uk_scraper.data;
#nullable disable
namespace lottery_co_uk_scraper.data.Migrations
{
[DbContext(typeof(LotteryContext))]
[Migration("20240207223729_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("lottery_co_uk_scraper.core.Models.LottoResult", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BallSetUsed")
.HasColumnType("int");
b.Property<DateOnly>("DrawDate")
.HasColumnType("date");
b.Property<int>("DrawNumber")
.HasColumnType("int");
b.Property<int>("DrawnBall1")
.HasColumnType("int");
b.Property<int>("DrawnBall2")
.HasColumnType("int");
b.Property<int>("DrawnBall3")
.HasColumnType("int");
b.Property<int>("DrawnBall4")
.HasColumnType("int");
b.Property<int>("DrawnBall5")
.HasColumnType("int");
b.Property<int>("DrawnBall6")
.HasColumnType("int");
b.Property<int>("DrawnBonusBall")
.HasColumnType("int");
b.Property<string>("MachineUsed")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<decimal>("Matched2Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched2PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched2RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched3Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched3PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched3RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched4Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched4PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched4RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5PlusBonusPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5PlusBonusPrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5PlusBonusRolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched6Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched6PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched6RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<bool>("Rolldown")
.HasColumnType("bit");
b.Property<bool>("Rollover")
.HasColumnType("bit");
b.Property<decimal>("TotalMatched2")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched3")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched4")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched5")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched5PlusBonus")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched6")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalPrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<int>("TotalWinners")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("LottoResults");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,73 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace lottery_co_uk_scraper.data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "LottoResults",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DrawDate = table.Column<DateOnly>(type: "date", nullable: false),
DrawNumber = table.Column<int>(type: "int", nullable: false),
Rollover = table.Column<bool>(type: "bit", nullable: false),
Rolldown = table.Column<bool>(type: "bit", nullable: false),
BallSetUsed = table.Column<int>(type: "int", nullable: false),
MachineUsed = table.Column<string>(type: "nvarchar(max)", nullable: false),
DrawnBall1 = table.Column<int>(type: "int", nullable: false),
DrawnBall2 = table.Column<int>(type: "int", nullable: false),
DrawnBall3 = table.Column<int>(type: "int", nullable: false),
DrawnBall4 = table.Column<int>(type: "int", nullable: false),
DrawnBall5 = table.Column<int>(type: "int", nullable: false),
DrawnBall6 = table.Column<int>(type: "int", nullable: false),
DrawnBonusBall = table.Column<int>(type: "int", nullable: false),
TotalMatched2 = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched2Prize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched2PrizeFund = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched2RolldownPrize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
TotalMatched3 = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched3Prize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched3PrizeFund = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched3RolldownPrize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
TotalMatched4 = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched4Prize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched4PrizeFund = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched4RolldownPrize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
TotalMatched5 = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched5Prize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched5PrizeFund = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
TotalMatched5PlusBonus = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched5RolldownPrize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched5PlusBonusPrize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched5PlusBonusPrizeFund = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched5PlusBonusRolldownPrize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
TotalMatched6 = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched6Prize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched6PrizeFund = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Matched6RolldownPrize = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
TotalWinners = table.Column<int>(type: "int", nullable: false),
TotalPrizeFund = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LottoResults", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "LottoResults");
}
}
}

View File

@@ -0,0 +1,158 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using lottery_co_uk_scraper.data;
#nullable disable
namespace lottery_co_uk_scraper.data.Migrations
{
[DbContext(typeof(LotteryContext))]
partial class LotteryContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("lottery_co_uk_scraper.core.Models.LottoResult", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BallSetUsed")
.HasColumnType("int");
b.Property<DateOnly>("DrawDate")
.HasColumnType("date");
b.Property<int>("DrawNumber")
.HasColumnType("int");
b.Property<int>("DrawnBall1")
.HasColumnType("int");
b.Property<int>("DrawnBall2")
.HasColumnType("int");
b.Property<int>("DrawnBall3")
.HasColumnType("int");
b.Property<int>("DrawnBall4")
.HasColumnType("int");
b.Property<int>("DrawnBall5")
.HasColumnType("int");
b.Property<int>("DrawnBall6")
.HasColumnType("int");
b.Property<int>("DrawnBonusBall")
.HasColumnType("int");
b.Property<string>("MachineUsed")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<decimal>("Matched2Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched2PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched2RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched3Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched3PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched3RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched4Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched4PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched4RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5PlusBonusPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5PlusBonusPrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5PlusBonusRolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched5RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched6Prize")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched6PrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Matched6RolldownPrize")
.HasColumnType("decimal(18,2)");
b.Property<bool>("Rolldown")
.HasColumnType("bit");
b.Property<bool>("Rollover")
.HasColumnType("bit");
b.Property<decimal>("TotalMatched2")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched3")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched4")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched5")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched5PlusBonus")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalMatched6")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalPrizeFund")
.HasColumnType("decimal(18,2)");
b.Property<int>("TotalWinners")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("LottoResults");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -10,6 +10,10 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>

View File

@@ -10,6 +10,10 @@
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.58" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>