diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Books/IBookRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Books/IBookRepository.cs
new file mode 100644
index 00000000..ca279313
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Books/IBookRepository.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
+using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
+using Lumina.Application.Common.Models.Books;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Books;
+
+///
+/// Interface for the repository for books.
+///
+public interface IBookRepository : IRepository,
+ IInsertRepositoryAction,
+ IGetAllRepositoryAction
+{
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteAllRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteAllRepositoryAction.cs
new file mode 100644
index 00000000..0d0cf3bb
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteAllRepositoryAction.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using ErrorOr;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
+
+///
+/// Interface defining the "delete all" action for interacting with a generic persistance medium.
+///
+public interface IDeleteAllRepositoryAction
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Deletes all entities from the storage medium.
+ ///
+ /// An representing either a successfull operation, or an error.
+ Task> DeleteAllAsync();
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteByIdRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteByIdRepositoryAction.cs
new file mode 100644
index 00000000..e4727002
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteByIdRepositoryAction.cs
@@ -0,0 +1,22 @@
+#region ========================================================================= USING =====================================================================================
+using ErrorOr;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
+
+///
+/// Interface defining the "delete by id" action for interacting with a generic persistance medium.
+///
+/// The type used for the identifier of the respository. It should not be .
+public interface IDeleteByIdRepositoryAction where TId : notnull
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Deletes an element identified by from the storage medium.
+ ///
+ /// The id of the element to be deleted.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successfull operation, or an error.
+ Task> DeleteByIdAsync(TId id, CancellationToken cancellationToken);
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetAllRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetAllRepositoryAction.cs
new file mode 100644
index 00000000..4a2bba09
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetAllRepositoryAction.cs
@@ -0,0 +1,22 @@
+#region ========================================================================= USING =====================================================================================
+using ErrorOr;
+using Lumina.Application.Common.Models.Common;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
+
+///
+/// Interface defining the "get all" action for interacting with a generic persistance medium.
+///
+/// The type used as a result for the "get all" action. It should implement .
+public interface IGetAllRepositoryAction where TModel : IStorageEntity
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Gets all data of type from the storage medium.
+ ///
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either a collection of , or an error.
+ Task>> GetAllAsync(CancellationToken cancellationToken);
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetByIdRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetByIdRepositoryAction.cs
new file mode 100644
index 00000000..9cb18ba4
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetByIdRepositoryAction.cs
@@ -0,0 +1,25 @@
+#region ========================================================================= USING =====================================================================================
+using ErrorOr;
+using Lumina.Application.Common.Models.Common;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
+
+///
+/// Interface defining the "get by id" action for interacting with a generic persistance medium.
+///
+/// The type used as a result for the "get by id" action. It should implement .
+/// The type used for the identifier of the respository. It should not be .
+public interface IGetByIdRepositoryAction where TModel : IStorageEntity
+ where TId : notnull
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Gets an element of type identified by from the storage medium.
+ ///
+ /// The id of the element to get.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either a identified by , or an error.
+ Task> GetByIdAsync(TId id, CancellationToken cancellationToken);
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IInsertRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IInsertRepositoryAction.cs
new file mode 100644
index 00000000..189b19f5
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IInsertRepositoryAction.cs
@@ -0,0 +1,23 @@
+#region ========================================================================= USING =====================================================================================
+using ErrorOr;
+using Lumina.Application.Common.Models.Common;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
+
+///
+/// Interface defining the "insert" action for interacting with a generic persistance medium.
+///
+/// The type used for the insert action. It should implement .
+public interface IInsertRepositoryAction where TModel : IStorageEntity
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Saves an element of type in the storage medium.
+ ///
+ /// The element to be saved.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successfull operation, or an error.
+ Task> InsertAsync(TModel data, CancellationToken cancellationToken);
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IUpdateRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IUpdateRepositoryAction.cs
new file mode 100644
index 00000000..6233cc42
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IUpdateRepositoryAction.cs
@@ -0,0 +1,23 @@
+#region ========================================================================= USING =====================================================================================
+using ErrorOr;
+using Lumina.Application.Common.Models.Common;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
+
+///
+/// Interface defining the "update" action for interacting with a generic persistance medium.
+///
+/// The type used for the update action. It should implement .
+public interface IUpdateRepositoryAction where TModel : IStorageEntity
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Updates in the storage medium.
+ ///
+ /// The element that will be updated.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successfull operation, or an error.
+ Task> UpdateAsync(TModel data, CancellationToken cancellationToken);
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Base/IRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Base/IRepository.cs
new file mode 100644
index 00000000..57fc4a41
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Base/IRepository.cs
@@ -0,0 +1,13 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Models.Common;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Common.Base;
+
+///
+/// Interface for interaction with a generic persistance medium.
+///
+/// The type used for the repository. It should implement .
+public interface IRepository where TModel : IStorageEntity
+{
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
new file mode 100644
index 00000000..83932cbd
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
@@ -0,0 +1,32 @@
+namespace Lumina.Application.Common.DataAccess.UoW;
+
+///
+/// Interaction boundary with the Data Access Layer.
+///
+public interface IUnitOfWork
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Exposes a repository of type to the Business Layer.
+ ///
+ /// The type of the exposed repository.
+ /// A repository of type .
+ TRepository GetRepository();
+
+ ///
+ /// Saves all changes made to the database.
+ ///
+ /// Cancellation token that can be used to stop the execution.
+ Task SaveChangesAsync(CancellationToken cancellationToken);
+
+ ///
+ /// Opens a transaction.
+ ///
+ void OpenTransaction();
+
+ ///
+ /// Commits a transaction.
+ ///
+ void CommitTransaction();
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.Application/Common/Models/Common/IStorageEntity.cs b/src/Lumina.Application/Common/Models/Common/IStorageEntity.cs
new file mode 100644
index 00000000..1ee22c4c
--- /dev/null
+++ b/src/Lumina.Application/Common/Models/Common/IStorageEntity.cs
@@ -0,0 +1,24 @@
+namespace Lumina.Application.Common.Models.Common;
+
+///
+/// Interface for storage DTOs, enforces Id.
+///
+public interface IStorageEntity
+{
+ #region ==================================================================== PROPERTIES =================================================================================
+ ///
+ /// Gets or sets the identifier of the entity.
+ ///
+ Guid Id { get; init; }
+
+ ///
+ /// The time and date when the entity was added.
+ ///
+ DateTime Created { get; set; }
+
+ ///
+ /// The time and date when the entity was updated.
+ ///
+ DateTime? Updated { get; set; }
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs
new file mode 100644
index 00000000..58c56d9f
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs
@@ -0,0 +1,181 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Models.Books;
+using Lumina.Application.Common.Models.Common;
+using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+#endregion
+
+namespace Lumina.DataAccess.Common.Configuration;
+
+///
+/// Configures the entity mapping for the aggregate root.
+///
+public class BookConfiguration : IEntityTypeConfiguration
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Configures the entity.
+ ///
+ /// The builder to be used to configure the entity.
+ public void Configure(EntityTypeBuilder builder)
+ {
+ builder.ToTable("Books");
+ builder.HasKey(book => book.Id);
+ builder.Property(book => book.Id)
+ .ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
+ .HasColumnOrder(0);
+
+ builder.Property(book => book.Title).IsRequired().HasMaxLength(255).HasColumnOrder(1);
+ builder.Property(book => book.OriginalTitle).HasMaxLength(255).HasColumnOrder(2);
+ builder.Property(book => book.Description).HasMaxLength(2000).HasColumnOrder(3);
+ builder.Property(book => book.OriginalReleaseDate).HasColumnOrder(4);
+ builder.Property(book => book.OriginalReleaseYear).HasColumnOrder(5);
+ builder.Property(book => book.ReReleaseDate).HasColumnOrder(6);
+ builder.Property(book => book.ReReleaseYear).HasColumnOrder(7);
+ builder.Property(book => book.ReleaseCountry).HasColumnOrder(8);
+ builder.Property(book => book.ReleaseVersion).HasColumnOrder(9);
+ builder.Property(book => book.LanguageCode).HasColumnOrder(10);
+ builder.Property(book => book.LanguageName).HasColumnOrder(11);
+ builder.Property(book => book.LanguageNativeName).HasColumnOrder(12);
+ builder.Property(book => book.OriginalLanguageCode).HasColumnOrder(13);
+ builder.Property(book => book.OriginalLanguageName).HasColumnOrder(14);
+ builder.Property(book => book.OriginalLanguageNativeName).HasColumnOrder(15);
+ // since Tag is a Domain ValueObject (no identity), we need to configure it as a many-to-many relationship
+ builder.HasMany(book => book.Tags)
+ .WithMany()
+ .UsingEntity>(
+ "BookTags",
+ j => j.HasOne().WithMany().HasForeignKey("TagId"),
+ j => j.HasOne().WithMany().HasForeignKey("BookId"),
+ j =>
+ {
+ j.HasKey("BookId", "TagId");
+ j.ToTable("BookTags");
+ });
+
+ builder.HasMany(book => book.Genres)
+ .WithMany()
+ .UsingEntity>(
+ "BookGenres",
+ j => j.HasOne().WithMany().HasForeignKey("GenreId"),
+ j => j.HasOne().WithMany().HasForeignKey("BookId"),
+ j =>
+ {
+ j.HasKey("BookId", "GenreId");
+ j.ToTable("BookGenres");
+ });
+
+ builder.Property(book => book.Publisher).HasMaxLength(100).HasColumnOrder(16);
+ builder.Property(book => book.PageCount).HasColumnOrder(17);
+ builder.Property(book => book.Format).HasColumnOrder(18);
+ builder.Property(book => book.Edition).HasMaxLength(50).HasColumnOrder(19);
+ builder.Property(book => book.VolumeNumber).HasColumnOrder(20);
+ builder.Property(book => book.ASIN).HasMaxLength(10).HasColumnOrder(21);
+ builder.Property(book => book.GoodreadsId).HasColumnOrder(22);
+ builder.Property(book => book.LCCN).HasColumnOrder(23);
+ builder.Property(book => book.OCLCNumber).HasColumnOrder(24);
+ builder.Property(book => book.OpenLibraryId).HasMaxLength(50).HasColumnOrder(25);
+ builder.Property(book => book.LibraryThingId).HasMaxLength(50).HasColumnOrder(26);
+ builder.Property(book => book.GoogleBooksId).HasMaxLength(12).HasColumnOrder(27);
+ builder.Property(book => book.BarnesAndNobleId).HasMaxLength(10).HasColumnOrder(28);
+ builder.Property(book => book.AppleBooksId).HasColumnOrder(29);
+ builder.Property(book => book.Created).HasColumnOrder(30);
+ builder.Property(book => book.Updated).HasColumnOrder(31);
+
+ //builder.HasMany()
+ //.WithMany()
+ //.UsingEntity>(
+ // "BookContributors",
+ // j => j.HasOne().WithMany().HasForeignKey("ContributorId"),
+ // j => j.HasOne().WithMany().HasForeignKey("BookId"),
+ // j =>
+ // {
+ // j.HasKey("BookId", "ContributorId");
+ // j.ToTable("BookContributors");
+ // });
+
+ //builder.OwnsMany(book => book.ContributorIds, ownedBuilder =>
+ //{
+ // ownedBuilder.ToTable("BookContributors");
+ // ownedBuilder.WithOwner().HasForeignKey("BookId");
+ // ownedBuilder.Property(c => c.Id)
+ // .HasColumnName("ContributorId")
+ // .HasColumnType("uniqueidentifier");
+ // ownedBuilder.HasKey("BookId", "Id"); // Use the actual property name 'Id' here
+ //});
+
+ builder.OwnsMany(book => book.Ratings, ratingBuilder =>
+ {
+ ratingBuilder.ToTable("BookRatings");
+ ratingBuilder.WithOwner().HasForeignKey("BookId");
+ ratingBuilder.Property("Id").ValueGeneratedOnAdd();
+ ratingBuilder.HasKey("Id");
+
+ ratingBuilder.Property(r => r.Value)
+ .HasColumnType("decimal(3,2)")
+ .IsRequired();
+
+ ratingBuilder.Property(r => r.MaxValue)
+ .HasColumnType("decimal(3,2)")
+ .IsRequired();
+
+ ratingBuilder.Property(r => r.VoteCount)
+ .IsRequired(false);
+
+ ratingBuilder.Property(r => r.Source)
+ .HasConversion()
+ .HasMaxLength(50)
+ .IsRequired();
+ });
+
+ builder.OwnsMany(book => book.ISBNs, isbnBuilder =>
+ {
+ isbnBuilder.ToTable("BookISBNs");
+ isbnBuilder.WithOwner().HasForeignKey("BookId");
+ isbnBuilder.Property("Id").ValueGeneratedOnAdd();
+ isbnBuilder.HasKey("Id");
+
+ isbnBuilder.Property(isbn => isbn.Value)
+ .HasColumnName("ISBN")
+ .HasMaxLength(13)
+ .IsRequired();
+
+ isbnBuilder.Property(isbn => isbn.Format)
+ .HasConversion()
+ .HasMaxLength(6)
+ .IsRequired();
+ });
+ }
+ #endregion
+}
+
+public class TagConfiguration : IEntityTypeConfiguration
+{
+ public void Configure(EntityTypeBuilder builder)
+ {
+ builder.ToTable("Tags");
+ builder.HasKey(t => t.Name);
+ builder.Property(t => t.Name).IsRequired().HasMaxLength(50);
+ }
+}
+
+public class GenreConfiguration : IEntityTypeConfiguration
+{
+ public void Configure(EntityTypeBuilder builder)
+ {
+ builder.ToTable("Genres");
+ builder.HasKey(g => g.Name);
+ builder.Property(g => g.Name).IsRequired().HasMaxLength(50);
+ }
+}
+
+//public class ContributorConfiguration : IEntityTypeConfiguration
+//{
+// public void Configure(EntityTypeBuilder builder)
+// {
+// builder.ToTable("Contributors");
+// builder.HasKey(c => c.Id);
+// builder.Property(c => c.Id).ValueGeneratedNever();
+// }
+//}
\ No newline at end of file
diff --git a/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs b/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs
new file mode 100644
index 00000000..eb2d50e7
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs
@@ -0,0 +1,58 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.DataAccess.Core.UoW;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.EntityFrameworkCore;
+using System.Reflection;
+using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
+using Lumina.DataAccess.Core.Repositories.Common.Factory;
+using Lumina.Application.Common.DataAccess.UoW;
+#endregion
+
+namespace Lumina.DataAccess.Common.DependencyInjection;
+
+///
+/// Contains all services of the DataAccess layer.
+///
+public static class DataAccessLayerServices
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Extension method for adding the DataAccess layer services to the DI container.
+ ///
+ /// The service collection to add the services to.
+ /// The updated .
+ public static void AddDataAccessLayerServices(this IServiceCollection services)
+ {
+ var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ if (!Directory.Exists(basePath))
+ throw new DirectoryNotFoundException($"The base path '{basePath}' does not exist.");
+ services.AddDbContext(options =>
+ {
+ options.UseSqlite($"Data Source={Path.Combine(basePath, "Lumina.db")}");
+ });
+
+ services.AddScoped();
+
+ Type[]? dataAccessLayerTypes = Assembly.GetExecutingAssembly().GetTypes();
+ Type? genericRepositoryType = typeof(IRepository<>);
+ Type? repositoryFactoryType = typeof(RepositoryFactory);
+ Type? iRepositoryFactoryType = typeof(IRepositoryFactory);
+
+ services.AddScoped(iRepositoryFactoryType!, repositoryFactoryType!);
+
+ // get all classes implementing IRepository (all repository classes) and register them as their corresponding repository interface
+ IEnumerable repositoryTypes = dataAccessLayerTypes.Where(t => !t.IsInterface &&
+ t.GetInterfaces()
+ .Any(i => i.IsGenericType &&
+ i.GetGenericTypeDefinition() == genericRepositoryType));
+ foreach (Type type in repositoryTypes)
+ {
+ services.AddScoped(type.GetInterfaces() // TODO: change to scoped when DbContext is implemented
+ .Where(i => !i.IsGenericType &&
+ i.GetInterfaces()
+ .Any(j => j.GetGenericTypeDefinition() == genericRepositoryType))
+ .First(), type);
+ }
+ }
+ #endregion
+}
diff --git a/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.Designer.cs
new file mode 100644
index 00000000..8c89d1b1
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.Designer.cs
@@ -0,0 +1,324 @@
+//
+using System;
+using Lumina.DataAccess.Core.UoW;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace Lumina.DataAccess.Common.Migrations
+{
+ [DbContext(typeof(LuminaDbContext))]
+ [Migration("20240826201057_InitialMigration")]
+ partial class InitialMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("BookGenres", (string)null);
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("BookTags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ASIN")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(21);
+
+ b.Property("AppleBooksId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(29);
+
+ b.Property("BarnesAndNobleId")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(28);
+
+ b.Property("Created")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(30);
+
+ b.Property("Description")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("Edition")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(19);
+
+ b.Property("Format")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(18);
+
+ b.Property("GoodreadsId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(22);
+
+ b.Property("GoogleBooksId")
+ .HasMaxLength(12)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(27);
+
+ b.Property("LCCN")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(23);
+
+ b.Property("LanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("LanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("LanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("LibraryThingId")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(26);
+
+ b.Property("OCLCNumber")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(24);
+
+ b.Property("OpenLibraryId")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(25);
+
+ b.Property("OriginalLanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("OriginalLanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("OriginalLanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(15);
+
+ b.Property("OriginalReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("OriginalReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("OriginalTitle")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("PageCount")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(17);
+
+ b.Property("Publisher")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(16);
+
+ b.Property("ReReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("ReReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(7);
+
+ b.Property("ReleaseCountry")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("ReleaseVersion")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("Title")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Updated")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(31);
+
+ b.Property("VolumeNumber")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(20);
+
+ b.HasKey("Id");
+
+ b.ToTable("Books", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Genres", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Tags", (string)null);
+ });
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
+ .WithMany()
+ .HasForeignKey("BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null)
+ .WithMany()
+ .HasForeignKey("GenreId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
+ .WithMany()
+ .HasForeignKey("BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null)
+ .WithMany()
+ .HasForeignKey("TagId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
+ {
+ b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 =>
+ {
+ b1.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b1.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b1.Property("MaxValue")
+ .HasColumnType("decimal(3,2)");
+
+ b1.Property("Source")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b1.Property("Value")
+ .HasColumnType("decimal(3,2)");
+
+ b1.Property("VoteCount")
+ .HasColumnType("INTEGER");
+
+ b1.HasKey("Id");
+
+ b1.HasIndex("BookId");
+
+ b1.ToTable("BookRatings", (string)null);
+
+ b1.WithOwner()
+ .HasForeignKey("BookId");
+ });
+
+ b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 =>
+ {
+ b1.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b1.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b1.Property("Format")
+ .IsRequired()
+ .HasMaxLength(6)
+ .HasColumnType("TEXT");
+
+ b1.Property("Value")
+ .IsRequired()
+ .HasMaxLength(13)
+ .HasColumnType("TEXT")
+ .HasColumnName("ISBN");
+
+ b1.HasKey("Id");
+
+ b1.HasIndex("BookId");
+
+ b1.ToTable("BookISBNs", (string)null);
+
+ b1.WithOwner()
+ .HasForeignKey("BookId");
+ });
+
+ b.Navigation("ISBNs");
+
+ b.Navigation("Ratings");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.cs b/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.cs
new file mode 100644
index 00000000..728c6d60
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.cs
@@ -0,0 +1,216 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace Lumina.DataAccess.Common.Migrations
+{
+ ///
+ public partial class InitialMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Books",
+ columns: table => new
+ {
+ Id = table.Column(type: "TEXT", nullable: false),
+ Title = table.Column(type: "TEXT", maxLength: 255, nullable: false),
+ OriginalTitle = table.Column(type: "TEXT", maxLength: 255, nullable: true),
+ Description = table.Column(type: "TEXT", maxLength: 2000, nullable: true),
+ OriginalReleaseDate = table.Column(type: "TEXT", nullable: true),
+ OriginalReleaseYear = table.Column(type: "INTEGER", nullable: true),
+ ReReleaseDate = table.Column(type: "TEXT", nullable: true),
+ ReReleaseYear = table.Column(type: "INTEGER", nullable: true),
+ ReleaseCountry = table.Column(type: "TEXT", nullable: true),
+ ReleaseVersion = table.Column(type: "TEXT", nullable: true),
+ LanguageCode = table.Column(type: "TEXT", nullable: true),
+ LanguageName = table.Column(type: "TEXT", nullable: true),
+ LanguageNativeName = table.Column(type: "TEXT", nullable: true),
+ OriginalLanguageCode = table.Column(type: "TEXT", nullable: true),
+ OriginalLanguageName = table.Column(type: "TEXT", nullable: true),
+ OriginalLanguageNativeName = table.Column(type: "TEXT", nullable: true),
+ Publisher = table.Column(type: "TEXT", maxLength: 100, nullable: true),
+ PageCount = table.Column(type: "INTEGER", nullable: true),
+ Format = table.Column(type: "TEXT", nullable: false),
+ Edition = table.Column(type: "TEXT", maxLength: 50, nullable: true),
+ VolumeNumber = table.Column(type: "INTEGER", nullable: true),
+ ASIN = table.Column(type: "TEXT", maxLength: 10, nullable: true),
+ GoodreadsId = table.Column(type: "TEXT", nullable: true),
+ LCCN = table.Column(type: "TEXT", nullable: true),
+ OCLCNumber = table.Column(type: "TEXT", nullable: true),
+ OpenLibraryId = table.Column(type: "TEXT", maxLength: 50, nullable: true),
+ LibraryThingId = table.Column(type: "TEXT", maxLength: 50, nullable: true),
+ GoogleBooksId = table.Column(type: "TEXT", maxLength: 12, nullable: true),
+ BarnesAndNobleId = table.Column(type: "TEXT", maxLength: 10, nullable: true),
+ AppleBooksId = table.Column(type: "TEXT", nullable: true),
+ Created = table.Column(type: "TEXT", nullable: false),
+ Updated = table.Column(type: "TEXT", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Books", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Genres",
+ columns: table => new
+ {
+ Name = table.Column(type: "TEXT", maxLength: 50, nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Genres", x => x.Name);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Tags",
+ columns: table => new
+ {
+ Name = table.Column(type: "TEXT", maxLength: 50, nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Tags", x => x.Name);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "BookISBNs",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ ISBN = table.Column(type: "TEXT", maxLength: 13, nullable: false),
+ Format = table.Column(type: "TEXT", maxLength: 6, nullable: false),
+ BookId = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_BookISBNs", x => x.Id);
+ table.ForeignKey(
+ name: "FK_BookISBNs_Books_BookId",
+ column: x => x.BookId,
+ principalTable: "Books",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "BookRatings",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Source = table.Column(type: "TEXT", maxLength: 50, nullable: false),
+ BookId = table.Column(type: "TEXT", nullable: false),
+ Value = table.Column(type: "decimal(3,2)", nullable: false),
+ MaxValue = table.Column(type: "decimal(3,2)", nullable: false),
+ VoteCount = table.Column(type: "INTEGER", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_BookRatings", x => x.Id);
+ table.ForeignKey(
+ name: "FK_BookRatings_Books_BookId",
+ column: x => x.BookId,
+ principalTable: "Books",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "BookGenres",
+ columns: table => new
+ {
+ BookId = table.Column(type: "TEXT", nullable: false),
+ GenreId = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_BookGenres", x => new { x.BookId, x.GenreId });
+ table.ForeignKey(
+ name: "FK_BookGenres_Books_BookId",
+ column: x => x.BookId,
+ principalTable: "Books",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_BookGenres_Genres_GenreId",
+ column: x => x.GenreId,
+ principalTable: "Genres",
+ principalColumn: "Name",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "BookTags",
+ columns: table => new
+ {
+ BookId = table.Column(type: "TEXT", nullable: false),
+ TagId = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_BookTags", x => new { x.BookId, x.TagId });
+ table.ForeignKey(
+ name: "FK_BookTags_Books_BookId",
+ column: x => x.BookId,
+ principalTable: "Books",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_BookTags_Tags_TagId",
+ column: x => x.TagId,
+ principalTable: "Tags",
+ principalColumn: "Name",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_BookGenres_GenreId",
+ table: "BookGenres",
+ column: "GenreId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_BookISBNs_BookId",
+ table: "BookISBNs",
+ column: "BookId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_BookRatings_BookId",
+ table: "BookRatings",
+ column: "BookId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_BookTags_TagId",
+ table: "BookTags",
+ column: "TagId");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "BookGenres");
+
+ migrationBuilder.DropTable(
+ name: "BookISBNs");
+
+ migrationBuilder.DropTable(
+ name: "BookRatings");
+
+ migrationBuilder.DropTable(
+ name: "BookTags");
+
+ migrationBuilder.DropTable(
+ name: "Genres");
+
+ migrationBuilder.DropTable(
+ name: "Books");
+
+ migrationBuilder.DropTable(
+ name: "Tags");
+ }
+ }
+}
diff --git a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs
new file mode 100644
index 00000000..9068a83e
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs
@@ -0,0 +1,321 @@
+//
+using System;
+using Lumina.DataAccess.Core.UoW;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace Lumina.DataAccess.Common.Migrations
+{
+ [DbContext(typeof(LuminaDbContext))]
+ partial class LuminaDbContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("BookGenres", (string)null);
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("BookTags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ASIN")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(21);
+
+ b.Property("AppleBooksId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(29);
+
+ b.Property("BarnesAndNobleId")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(28);
+
+ b.Property("Created")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(30);
+
+ b.Property("Description")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("Edition")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(19);
+
+ b.Property("Format")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(18);
+
+ b.Property("GoodreadsId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(22);
+
+ b.Property("GoogleBooksId")
+ .HasMaxLength(12)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(27);
+
+ b.Property("LCCN")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(23);
+
+ b.Property("LanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("LanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("LanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("LibraryThingId")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(26);
+
+ b.Property("OCLCNumber")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(24);
+
+ b.Property("OpenLibraryId")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(25);
+
+ b.Property("OriginalLanguageCode")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("OriginalLanguageName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("OriginalLanguageNativeName")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(15);
+
+ b.Property("OriginalReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("OriginalReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("OriginalTitle")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("PageCount")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(17);
+
+ b.Property("Publisher")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(16);
+
+ b.Property("ReReleaseDate")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("ReReleaseYear")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(7);
+
+ b.Property("ReleaseCountry")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("ReleaseVersion")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("Title")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Updated")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(31);
+
+ b.Property("VolumeNumber")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(20);
+
+ b.HasKey("Id");
+
+ b.ToTable("Books", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Genres", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Tags", (string)null);
+ });
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
+ .WithMany()
+ .HasForeignKey("BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null)
+ .WithMany()
+ .HasForeignKey("GenreId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
+ .WithMany()
+ .HasForeignKey("BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null)
+ .WithMany()
+ .HasForeignKey("TagId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
+ {
+ b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 =>
+ {
+ b1.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b1.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b1.Property("MaxValue")
+ .HasColumnType("decimal(3,2)");
+
+ b1.Property("Source")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b1.Property("Value")
+ .HasColumnType("decimal(3,2)");
+
+ b1.Property("VoteCount")
+ .HasColumnType("INTEGER");
+
+ b1.HasKey("Id");
+
+ b1.HasIndex("BookId");
+
+ b1.ToTable("BookRatings", (string)null);
+
+ b1.WithOwner()
+ .HasForeignKey("BookId");
+ });
+
+ b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 =>
+ {
+ b1.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b1.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b1.Property("Format")
+ .IsRequired()
+ .HasMaxLength(6)
+ .HasColumnType("TEXT");
+
+ b1.Property("Value")
+ .IsRequired()
+ .HasMaxLength(13)
+ .HasColumnType("TEXT")
+ .HasColumnName("ISBN");
+
+ b1.HasKey("Id");
+
+ b1.HasIndex("BookId");
+
+ b1.ToTable("BookISBNs", (string)null);
+
+ b1.WithOwner()
+ .HasForeignKey("BookId");
+ });
+
+ b.Navigation("ISBNs");
+
+ b.Navigation("Ratings");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/Lumina.DataAccess/Core/Repositories/Books/BookRepository.cs b/src/Lumina.DataAccess/Core/Repositories/Books/BookRepository.cs
new file mode 100644
index 00000000..ca9ab07d
--- /dev/null
+++ b/src/Lumina.DataAccess/Core/Repositories/Books/BookRepository.cs
@@ -0,0 +1,58 @@
+#region ========================================================================= USING =====================================================================================
+using ErrorOr;
+using Lumina.Application.Common.DataAccess.Repositories.Books;
+using Lumina.Application.Common.Models.Books;
+using Lumina.DataAccess.Core.UoW;
+using Lumina.Domain.Common.Errors;
+using Microsoft.EntityFrameworkCore;
+#endregion
+
+namespace Lumina.DataAccess.Core.Repositories.Books;
+
+///
+/// Repository for books.
+///
+internal sealed class BookRepository : IBookRepository
+{
+ #region ================================================================== FIELD MEMBERS ================================================================================
+ private readonly LuminaDbContext _luminaDbContext;
+ #endregion
+
+ #region ====================================================================== CTOR =====================================================================================
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected Entity Framework DbContext.
+ public BookRepository(LuminaDbContext luminaDbContext)
+ {
+ _luminaDbContext = luminaDbContext;
+ }
+ #endregion
+
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Adds a new book.
+ ///
+ /// The book to add.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successfull operation, or an error.
+ public async Task> InsertAsync(BookDto book, CancellationToken cancellationToken)
+ {
+ var jobExists = await _luminaDbContext.Books.AnyAsync(_book => _book.Id == book.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
+ if (jobExists)
+ return Errors.WrittenContent.BookAlreadyExists;
+ _luminaDbContext.Books.Add(book);
+ return Result.Created;
+ }
+
+ ///
+ /// Gets all books.
+ ///
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either a collection of , or an error.
+ public async Task>> GetAllAsync(CancellationToken cancellationToken)
+ {
+ return await _luminaDbContext.Books.ToListAsync(cancellationToken).ConfigureAwait(false);
+ }
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/IRepositoryFactory.cs b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/IRepositoryFactory.cs
new file mode 100644
index 00000000..a6e6a762
--- /dev/null
+++ b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/IRepositoryFactory.cs
@@ -0,0 +1,16 @@
+namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
+
+///
+/// Repositories abstract factory.
+///
+public interface IRepositoryFactory
+{
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Creates a new repository of type .
+ ///
+ /// The type of repository to create.
+ /// A repository of type .
+ TResult CreateRepository() where TResult : notnull;
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryDictionary.cs b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryDictionary.cs
new file mode 100644
index 00000000..6e0a1b4f
--- /dev/null
+++ b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryDictionary.cs
@@ -0,0 +1,64 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
+#endregion
+
+namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
+
+///
+/// Custom collection for storing repositories.
+///
+public class RepositoryDictionary
+{
+ #region ================================================================== FIELD MEMBERS ================================================================================
+ private readonly List> _container = [];
+ #endregion
+
+ #region ==================================================================== PROPERTIES =================================================================================
+ public int Count { get { return _container.Count; } }
+ #endregion
+
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Resets the collection of repositories.
+ ///
+ public void Clear()
+ {
+ _container.Clear();
+ }
+
+ ///
+ /// Adds a repository of type to the collection.
+ ///
+ /// The type of the repository to add to the collection.
+ /// The repository to add.
+ public void Add(TParam value) where TParam : notnull
+ {
+ // enforce adding rules
+ if (value == null)
+ throw new ArgumentException("Value cannot be null!");
+ if (_container.Any(e => e.Key == value.GetType()))
+ throw new ArgumentException("Duplicate values are not allowed!");
+ // check if the value implements an interface that implements IRepository
+ bool implementsRepository = value.GetType()
+ .GetInterfaces()
+ .Any(e => e.GetInterfaces()
+ .Any(i => i.IsGenericType &&
+ i.GetGenericTypeDefinition() == typeof(IRepository<>)));
+ if (implementsRepository)
+ _container.Add(new KeyValuePair(value.GetType(), value));
+ else
+ throw new ArgumentException("Value must implement IRepository interface!");
+ }
+
+ ///
+ /// Gets a repository of type from the collection.
+ ///
+ /// The type of the repository interface to get from the collection.
+ /// The concrete type of the repository interface to get.
+ /// A repository implementing .
+ public TResult Get(Type key)
+ {
+ return (TResult)_container.FirstOrDefault(e => e.Key == key).Value;
+ }
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryFactory.cs b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryFactory.cs
new file mode 100644
index 00000000..243eddfa
--- /dev/null
+++ b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryFactory.cs
@@ -0,0 +1,39 @@
+#region ========================================================================= USING =====================================================================================
+using Microsoft.Extensions.DependencyInjection;
+#endregion
+
+namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
+
+///
+/// Concrete implementation for the repositories abstract factory.
+///
+public class RepositoryFactory : IRepositoryFactory
+{
+ #region ================================================================== FIELD MEMBERS ================================================================================
+ private readonly IServiceProvider _serviceProvider;
+ #endregion
+
+ #region ====================================================================== CTOR =====================================================================================
+ ///
+ /// Overload C-tor.
+ ///
+ /// The service provider.
+ public RepositoryFactory(IServiceProvider serviceProvider)
+ {
+ _serviceProvider = serviceProvider;
+ }
+ #endregion
+
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Creates a new repository of type .
+ ///
+ /// The type of repository to create.
+ /// A repository of type .
+ /// Thrown when the type of the requested repository has not been registered.
+ public TResult CreateRepository() where TResult : notnull
+ {
+ return _serviceProvider.GetRequiredService() ?? throw new ArgumentException();
+ }
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs
new file mode 100644
index 00000000..de9c2984
--- /dev/null
+++ b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs
@@ -0,0 +1,68 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Models.Books;
+using Lumina.Application.Common.Models.Common;
+using Lumina.Domain.Common.Events;
+using Microsoft.EntityFrameworkCore;
+#endregion
+
+namespace Lumina.DataAccess.Core.UoW;
+
+///
+/// DbContext for the Lumina application.
+///
+/// To add a new migration: add-migration InitialMigration -p Lumina.DataAccess -s Lumina.Presentation.Api -o Common\Migrations
+/// To update the database: update-database -p Lumina.DataAccess -s Lumina.Presentation.Api
+public class LuminaDbContext : DbContext
+{
+ #region ==================================================================== PROPERTIES =================================================================================
+ public DbSet Books { get; set; } = null!;
+ #endregion
+
+ #region ====================================================================== CTOR =====================================================================================
+ ///
+ /// Overload C-tor.
+ ///
+ /// The options for configuring the database context.
+ public LuminaDbContext(DbContextOptions options) : base(options)
+ {
+ }
+ #endregion
+
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Configures the entity mappings for the database context.
+ ///
+ /// The model builder used to configure the entity mappings.
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ // find all the entity configurations in the assembly and apply them
+ modelBuilder
+ .Ignore>()
+ .ApplyConfigurationsFromAssembly(typeof(LuminaDbContext).Assembly);
+
+ base.OnModelCreating(modelBuilder);
+ }
+
+ ///
+ /// Overrides the SaveChanges method of the DbContext class to automatically set the Created and Updated properties of entities that implement the .
+ ///
+ /// The number of objects written to the underlying database.
+ public override int SaveChanges()
+ {
+ // get all the entity entries that are either added or modified
+ var entries = ChangeTracker.Entries()
+ .Where(e => e.Entity is IStorageEntity &&
+ (e.State is EntityState.Added or EntityState.Modified));
+ foreach (var entityEntry in entries)
+ {
+ // if the entity is in Added state, set the Created property to the current date and time
+ if (entityEntry.State == EntityState.Added)
+ ((IStorageEntity)entityEntry.Entity).Created = DateTime.UtcNow;
+ // otherwise, if the entity is in Modified state, set the Updated property to the current date and time
+ else if (entityEntry.State == EntityState.Modified)
+ ((IStorageEntity)entityEntry.Entity).Updated = DateTime.UtcNow;
+ }
+ return base.SaveChanges();
+ }
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs
new file mode 100644
index 00000000..d6d189f2
--- /dev/null
+++ b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs
@@ -0,0 +1,117 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.DataAccess.Core.Repositories.Common.Factory;
+using System.Reflection;
+#endregion
+
+namespace Lumina.DataAccess.Core.UoW;
+
+///
+/// Interaction boundary with the Data Access Layer.
+///
+public class UnitOfWork : IUnitOfWork
+{
+ #region ================================================================== FIELD MEMBERS ================================================================================
+ private readonly LuminaDbContext _luminaDbContext;
+ private readonly IRepositoryFactory _repositoryFactory;
+ #endregion
+
+ #region ==================================================================== PROPERTIES =================================================================================
+ internal RepositoryDictionary Repositories { get; private set; } = new RepositoryDictionary();
+ #endregion
+
+ #region ====================================================================== CTOR =====================================================================================
+ ///
+ /// Overload C-tor.
+ ///
+ /// The abstract factory used to generate repositories.
+ /// Injected Entity Framework DbContext.
+ public UnitOfWork(IRepositoryFactory repositoryFactory, LuminaDbContext luminaDbContext)
+ {
+ _repositoryFactory = repositoryFactory;
+ _luminaDbContext = luminaDbContext;
+ AddRepositories();
+ }
+ #endregion
+
+ #region ===================================================================== METHODS ===================================================================================
+ ///
+ /// Adds all the repositories from the Data Access Layer so that they can be exposed to the Business Layer.
+ ///
+ internal void AddRepositories()
+ {
+ // get all the concrete implementations of IRepository<>
+ IEnumerable repositoryClassTypes =
+ Assembly.GetExecutingAssembly()
+ .GetTypes()
+ .Where(t => !t.IsInterface && !t.IsAbstract && t.GetInterfaces()
+ .Any(i => i.IsGenericType &&
+ i.GetGenericTypeDefinition() == typeof(IRepository<>)));
+ // store all repositories
+ foreach (Type repositoryClassType in repositoryClassTypes)
+ {
+ // get the interface that implements IRepository<> of the currently iterated repository class
+ Type repositoryInterfaceType = repositoryClassType.GetInterfaces()
+ .Where(i => !i.IsGenericType &&
+ i.GetInterfaces()
+ .Any(a => a.GetGenericTypeDefinition() == typeof(IRepository<>)))
+ .First();
+ // ask the concrete type for the repository interface type from the repositories factory;
+ // because the method for creating a repository is generic and we need to call it with a runtime type, reflection is the only option
+ object repositoryClass = typeof(IRepositoryFactory).GetMethod("CreateRepository")!
+ .MakeGenericMethod(repositoryInterfaceType)
+ .Invoke(_repositoryFactory, null)!;
+ Repositories.Add(repositoryClass);
+ }
+ }
+
+ ///
+ /// Exposes a repository of type to the Business Logic Layer.
+ ///
+ /// The type of the exposed repository.
+ /// A repository of type .
+ public TRepository GetRepository()
+ {
+ // get the repository type based on the type of the provided repository interface
+ Type repositoryType = Assembly.GetExecutingAssembly()
+ .GetTypes()
+ .Where(type => !type.IsInterface && !type.IsAbstract && typeof(TRepository).IsAssignableFrom(type))
+ .First();
+ return Repositories.Get(repositoryType);
+ }
+
+ ///
+ /// Resets the list of repositories.
+ ///
+ internal void ResetRepositories()
+ {
+ Repositories.Clear();
+ }
+
+ ///
+ /// Saves the changes made to the database.
+ ///
+ /// Cancellation token that can be used to stop the execution.
+ public async Task SaveChangesAsync(CancellationToken cancellationToken)
+ {
+ await _luminaDbContext.SaveChangesAsync(cancellationToken);
+ }
+
+ ///
+ /// Opens a transaction.
+ ///
+ public void OpenTransaction()
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// Commits a transaction.
+ ///
+ public void CommitTransaction()
+ {
+ throw new NotImplementedException();
+ }
+ #endregion
+}
\ No newline at end of file
diff --git a/src/Lumina.DataAccess/Lumina.DataAccess.csproj b/src/Lumina.DataAccess/Lumina.DataAccess.csproj
index 1eadaafa..fba4de1e 100644
--- a/src/Lumina.DataAccess/Lumina.DataAccess.csproj
+++ b/src/Lumina.DataAccess/Lumina.DataAccess.csproj
@@ -1,14 +1,32 @@
-
- net8.0
- enable
- enable
- ..\..\bin\
-
+
+ net8.0
+ enable
+ enable
+ ..\..\bin\
+
-
-
-
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
diff --git a/src/Lumina.Domain/Common/Errors/Errors.WrittenContent.cs b/src/Lumina.Domain/Common/Errors/Errors.WrittenContent.cs
index a46e2ca3..9cd2cebb 100644
--- a/src/Lumina.Domain/Common/Errors/Errors.WrittenContent.cs
+++ b/src/Lumina.Domain/Common/Errors/Errors.WrittenContent.cs
@@ -12,6 +12,7 @@ public static partial class Errors
public static class WrittenContent
{
#region ==================================================================== PROPERTIES =================================================================================
+ public static Error BookAlreadyExists => Error.Conflict(nameof(BookAlreadyExists));
public static Error IsbnValueCannotBeEmpty => Error.Validation(nameof(IsbnValueCannotBeEmpty));
public static Error IsbnListCannotBeNull => Error.Validation(nameof(IsbnListCannotBeNull));
public static Error InvalidIsbn10Format => Error.Validation(nameof(InvalidIsbn10Format));
diff --git a/src/Lumina.Domain/Common/Events/IDomainEvent.cs b/src/Lumina.Domain/Common/Events/IDomainEvent.cs
new file mode 100644
index 00000000..d07ba628
--- /dev/null
+++ b/src/Lumina.Domain/Common/Events/IDomainEvent.cs
@@ -0,0 +1,12 @@
+namespace Lumina.Domain.Common.Events;
+
+///
+/// Interface defining a domain event.
+///
+public interface IDomainEvent
+{
+ #region ==================================================================== PROPERTIES =================================================================================
+ Guid Id { get; }
+ DateTime OccurredOn { get; }
+ #endregion
+}
\ No newline at end of file