-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Domain.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Infrastructure.Configuration; | ||
|
||
public class BookConfiguration : IEntityTypeConfiguration<Book> | ||
{ | ||
public void Configure(EntityTypeBuilder<Book> builder) | ||
{ | ||
builder.HasMany(e => e.OrderDetails) | ||
.WithOne(e => e.Book) | ||
.HasPrincipalKey(e => e.Id) | ||
.HasForeignKey(e => e.BookId) | ||
.IsRequired(); | ||
|
||
builder.HasMany(e => e.BookCategories) | ||
.WithOne(e => e.Book) | ||
.HasPrincipalKey(e => e.Id) | ||
.HasForeignKey(e => e.BookId) | ||
.IsRequired(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Domain.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Infrastructure.Configuration; | ||
|
||
public class CategoryConfiguration : IEntityTypeConfiguration<Category> | ||
{ | ||
public void Configure(EntityTypeBuilder<Category> builder) | ||
{ | ||
builder.HasMany(e => e.BookCategories) | ||
.WithOne(e => e.Category) | ||
.HasPrincipalKey(e => e.Id) | ||
.HasForeignKey(e => e.BookId) | ||
.IsRequired(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Infrastructure/Configuration/ModelBuilderConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Infrastructure.Configuration; | ||
|
||
public class ModelBuilderConfiguration | ||
{ | ||
public static void Apply(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.ApplyConfiguration(new UserConfiguration()); | ||
modelBuilder.ApplyConfiguration(new CategoryConfiguration()); | ||
modelBuilder.ApplyConfiguration(new UserConfiguration()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Domain.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Infrastructure.Configuration; | ||
|
||
public class UserConfiguration : IEntityTypeConfiguration<User> | ||
{ | ||
public void Configure(EntityTypeBuilder<User> builder) | ||
{ | ||
builder.HasMany(e => e.Orders) | ||
.WithOne(e => e.User) | ||
.HasPrincipalKey(e => e.UserName) | ||
.HasForeignKey(e => e.UserName) | ||
.IsRequired(); | ||
} | ||
} |