Skip to content

Commit a10c528

Browse files
committed
update model for resource separation example in base example src
1 parent b6df7c6 commit a10c528

14 files changed

+684
-51
lines changed

src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using JsonApiDotNetCoreExample.Models;
22
using JsonApiDotNetCore.Models;
33
using Microsoft.EntityFrameworkCore;
4+
using JsonApiDotNetCoreExample.Models.Entities;
45

56
namespace JsonApiDotNetCoreExample.Data
67
{
@@ -24,6 +25,20 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2425
.HasOne(t => t.Owner)
2526
.WithMany(p => p.TodoItems)
2627
.HasForeignKey(t => t.OwnerId);
28+
29+
modelBuilder.Entity<CourseStudentEntity>()
30+
.HasKey(r => new { r.CourseId, r.StudentId });
31+
32+
modelBuilder.Entity<CourseStudentEntity>()
33+
.HasOne(r => r.Course)
34+
.WithMany(c => c.Students)
35+
.HasForeignKey(r => r.CourseId)
36+
;
37+
38+
modelBuilder.Entity<CourseStudentEntity>()
39+
.HasOne(r => r.Student)
40+
.WithMany(s => s.Courses)
41+
.HasForeignKey(r => r.StudentId);
2742
}
2843

2944
public DbSet<TodoItem> TodoItems { get; set; }
@@ -40,6 +55,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
4055
public DbSet<NonJsonApiResource> NonJsonApiResources { get; set; }
4156
public DbSet<User> Users { get; set; }
4257

58+
public DbSet<CourseEntity> Courses { get; set; }
59+
public DbSet<DepartmentEntity> Departments { get; set; }
60+
public DbSet<CourseStudentEntity> Registrations { get; set; }
4361
public DbSet<StudentEntity> Students { get; set; }
4462
}
4563
}

src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="2.1.0" />
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.1.0" />
1618
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftConfigurationVersion)" />
1719
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="$(MicrosoftConfigurationVersion)" />
1820
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftConfigurationVersion)" />

src/Examples/JsonApiDotNetCoreExample/Migrations/20180327120810_initial.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
149149
name: "IX_TodoItems_OwnerId",
150150
table: "TodoItems",
151151
column: "OwnerId");
152-
153-
migrationBuilder.CreateTable(
154-
name: "student",
155-
columns: table => new
156-
{
157-
Id = table.Column<int>(nullable: false)
158-
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
159-
firstname = table.Column<string>(name: "first-name", nullable: false),
160-
lastname = table.Column<string>(name: "last-name", maxLength: 255, nullable: false),
161-
address = table.Column<string>(nullable: true)
162-
},
163-
constraints: table =>
164-
{
165-
table.PrimaryKey("PK_student", x => x.Id);
166-
});
167152
}
168153

169154
protected override void Down(MigrationBuilder migrationBuilder)
@@ -185,9 +170,6 @@ protected override void Down(MigrationBuilder migrationBuilder)
185170

186171
migrationBuilder.DropTable(
187172
name: "People");
188-
189-
migrationBuilder.DropTable(
190-
name: "student");
191173
}
192174
}
193175
}

src/Examples/JsonApiDotNetCoreExample/Migrations/20180717134637_ResourceSeparation.Designer.cs

Lines changed: 296 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)