Fleshed out entity classes and created command to create student

This commit is contained in:
2019-04-24 23:57:55 +00:00
parent a30e9a5b1c
commit acba25cc0b
13 changed files with 129 additions and 27 deletions

View File

@@ -19,12 +19,13 @@ namespace BrightGlimmer.Data
// dotnet ef migrations update --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Api
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>()
.HasMany(x => x.Phones);
modelBuilder.Entity<Student>()
.HasOne(x => x.Address);
modelBuilder.Entity<Student>()
.HasMany(x => x.AssignedCourses);
modelBuilder.Entity<Student>(entity =>
{
entity.HasIndex(e => e.StudentNumber).IsUnique();
entity.HasOne(e => e.Address);
entity.HasMany(e => e.Phones);
entity.HasMany(e => e.AssignedCourses);
});
modelBuilder.Entity<AssignedCourse>()
.HasOne(x => x.Course);
}

View File

@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BrightGlimmer.Data.Migrations
{
[DbContext(typeof(BgContext))]
[Migration("20190424174147_CreateDatabase")]
[Migration("20190424233105_CreateDatabase")]
partial class CreateDatabase
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -157,6 +157,9 @@ namespace BrightGlimmer.Data.Migrations
b.HasIndex("AddressId");
b.HasIndex("StudentNumber")
.IsUnique();
b.ToTable("Students");
});

View File

@@ -147,6 +147,12 @@ namespace BrightGlimmer.Data.Migrations
name: "IX_Students_AddressId",
table: "Students",
column: "AddressId");
migrationBuilder.CreateIndex(
name: "IX_Students_StudentNumber",
table: "Students",
column: "StudentNumber",
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)

View File

@@ -155,6 +155,9 @@ namespace BrightGlimmer.Data.Migrations
b.HasIndex("AddressId");
b.HasIndex("StudentNumber")
.IsUnique();
b.ToTable("Students");
});

Binary file not shown.