diff --git a/Sources/EFLol/ChampionContext.cs b/Sources/EFLol/ChampionContext.cs index fd63455..d1333c0 100644 --- a/Sources/EFLol/ChampionContext.cs +++ b/Sources/EFLol/ChampionContext.cs @@ -9,11 +9,11 @@ namespace EFLol { internal class ChampionContext : DbContext { - public DbSet Champions { get; set; } + public DbSet Champions { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite("Data Source=Champions.db"); + optionsBuilder.UseSqlite("Data Source=loldb.db"); } } } diff --git a/Sources/EFLol/Champion.cs b/Sources/EFLol/ChampionEntity.cs similarity index 77% rename from Sources/EFLol/Champion.cs rename to Sources/EFLol/ChampionEntity.cs index c067647..e9fe819 100644 --- a/Sources/EFLol/Champion.cs +++ b/Sources/EFLol/ChampionEntity.cs @@ -6,8 +6,9 @@ using System.Threading.Tasks; namespace EFLol { - internal class Champion + internal class ChampionEntity { + public int Id { get; set; } public string Name { get; set; } public string Bio { get; set; } } diff --git a/Sources/EFLol/EFLol.csproj b/Sources/EFLol/EFLol.csproj index 4d8e532..c55d3a4 100644 --- a/Sources/EFLol/EFLol.csproj +++ b/Sources/EFLol/EFLol.csproj @@ -1,10 +1,11 @@ - + Exe net6.0 enable enable + $(MSBuildProjectDirectory) @@ -17,4 +18,5 @@ + diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs b/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs new file mode 100644 index 0000000..29614aa --- /dev/null +++ b/Sources/EFLol/Migrations/20230201162158_FirstMig.Designer.cs @@ -0,0 +1,43 @@ +// +using EFLol; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EFLol.Migrations +{ + [DbContext(typeof(ChampionContext))] + [Migration("20230201162158_FirstMig")] + partial class FirstMig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EFLol.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EFLol/Migrations/20230201162158_FirstMig.cs b/Sources/EFLol/Migrations/20230201162158_FirstMig.cs new file mode 100644 index 0000000..59c3ac5 --- /dev/null +++ b/Sources/EFLol/Migrations/20230201162158_FirstMig.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EFLol.Migrations +{ + /// + public partial class FirstMig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Bio = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Champions"); + } + } +} diff --git a/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs b/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs new file mode 100644 index 0000000..cf6018a --- /dev/null +++ b/Sources/EFLol/Migrations/ChampionContextModelSnapshot.cs @@ -0,0 +1,40 @@ +// +using EFLol; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EFLol.Migrations +{ + [DbContext(typeof(ChampionContext))] + partial class ChampionContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EFLol.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Champions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EFLol/Program.cs b/Sources/EFLol/Program.cs index 3751555..775f405 100644 --- a/Sources/EFLol/Program.cs +++ b/Sources/EFLol/Program.cs @@ -1,2 +1,14 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using EFLol; + +ChampionEntity Zeus = new ChampionEntity +{ + Name = "Zeus", + Bio = "Zeus is the king of the gods." +}; + +using (var context = new ChampionContext()) +{ + Console.WriteLine("Adding Zeus to the database..."); + context.Champions.Add(Zeus); + context.SaveChanges(); +} \ No newline at end of file diff --git a/Sources/EFLol/loldb.db b/Sources/EFLol/loldb.db new file mode 100644 index 0000000..ef35bd0 Binary files /dev/null and b/Sources/EFLol/loldb.db differ