Add initial database context and first entity
This commit is contained in:
27
Data/DiaryDBContext.cs
Normal file
27
Data/DiaryDBContext.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Diary.Component.Entry.Repository;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Diary.Data
|
||||
{
|
||||
|
||||
public interface IDiaryDBContext
|
||||
{
|
||||
DbSet<Entry> Entries { get; set; }
|
||||
}
|
||||
|
||||
public class DiaryDBContext : DbContext, IDiaryDBContext
|
||||
{
|
||||
public DbSet<Entry> Entries { get; set; }
|
||||
|
||||
public DiaryDBContext(DbContextOptions<DiaryDBContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.ApplyConfiguration(new EntryConfiguration());
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Data/Migrations/20220603063002_Initial.Designer.cs
generated
Normal file
55
Data/Migrations/20220603063002_Initial.Designer.cs
generated
Normal file
@@ -0,0 +1,55 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Diary.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Diary.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DiaryDBContext))]
|
||||
[Migration("20220603063002_Initial")]
|
||||
partial class Initial
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||
|
||||
modelBuilder.Entity("Diary.Component.Entry.Repository.Entry", b =>
|
||||
{
|
||||
b.Property<int>("EnrtyID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("EnrtyID"), 1L, 1);
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("Date");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ValidFrom")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("ValidTo")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("EnrtyID");
|
||||
|
||||
b.ToTable("Entries", "Diary");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Data/Migrations/20220603063002_Initial.cs
Normal file
40
Data/Migrations/20220603063002_Initial.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Diary.Data.Migrations
|
||||
{
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.EnsureSchema(
|
||||
name: "Diary");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Entries",
|
||||
schema: "Diary",
|
||||
columns: table => new
|
||||
{
|
||||
EnrtyID = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Date = table.Column<DateTime>(type: "Date", nullable: false),
|
||||
ValidFrom = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ValidTo = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
Note = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Entries", x => x.EnrtyID);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Entries",
|
||||
schema: "Diary");
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Data/Migrations/DiaryDBContextModelSnapshot.cs
Normal file
53
Data/Migrations/DiaryDBContextModelSnapshot.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Diary.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Diary.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DiaryDBContext))]
|
||||
partial class DiaryDBContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||
|
||||
modelBuilder.Entity("Diary.Component.Entry.Repository.Entry", b =>
|
||||
{
|
||||
b.Property<int>("EnrtyID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("EnrtyID"), 1L, 1);
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("Date");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ValidFrom")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("ValidTo")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("EnrtyID");
|
||||
|
||||
b.ToTable("Entries", "Diary");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user