Skip to content

Commit 6c785fc

Browse files
Merge pull request #14 from DilmurodDeveloper/users/DilmurodDeveloper/model-readerbook-add
MODEL: Add ReaderBook
2 parents 0119dbc + 5495d42 commit 6c785fc

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
using LibraryManagement.Api.Models.Foundations.ReaderBooks;
7+
using Microsoft.EntityFrameworkCore;
8+
9+
namespace LibraryManagement.Api.Brokers.Storages
10+
{
11+
public partial class StorageBroker
12+
{
13+
public DbSet<ReaderBook> ReaderBooks { get; set; }
14+
}
15+
}

LibraryManagement.Api/Brokers/Storages/StorageBroker.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//-----------------------------------------------------------
55

66
using EFxceptions;
7+
using LibraryManagement.Api.Models.Foundations.Books;
78
using Microsoft.EntityFrameworkCore;
89

910
namespace LibraryManagement.Api.Brokers.Storages
@@ -26,6 +27,16 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2627
optionsBuilder.UseSqlServer(connectionString);
2728
}
2829

30+
protected override void OnModelCreating(ModelBuilder modelBuilder)
31+
{
32+
modelBuilder.Entity<Book>()
33+
.HasOne(b => b.Reader)
34+
.WithMany(r => r.Books)
35+
.HasForeignKey(b => b.ReaderId);
36+
37+
base.OnModelCreating(modelBuilder);
38+
}
39+
2940
public override void Dispose() { }
3041
}
3142
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
using LibraryManagement.Api.Models.Foundations.Books;
7+
using LibraryManagement.Api.Models.Foundations.Readers;
8+
9+
namespace LibraryManagement.Api.Models.Foundations.ReaderBooks
10+
{
11+
public class ReaderBook
12+
{
13+
public Reader Reader { get; set; }
14+
public List<Book> Books { get; set; }
15+
}
16+
}

0 commit comments

Comments
 (0)