Refactoring, database structure changed
This commit is contained in:
90
WatchIt.Database/Configuration/Media/MediumConfiguration.cs
Normal file
90
WatchIt.Database/Configuration/Media/MediumConfiguration.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Media;
|
||||
|
||||
public class MediumConfiguration : IEntityTypeConfiguration<Medium>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<Medium> builder)
|
||||
{
|
||||
builder.ToTable("Media", "media");
|
||||
builder.HasDiscriminator<MediumType>("Type")
|
||||
.HasValue<MediumMovie>(MediumType.Movie)
|
||||
.HasValue<MediumSeries>(MediumType.Series);
|
||||
|
||||
// Id
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.HasIndex(x => x.Id)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.Id)
|
||||
.IsRequired()
|
||||
.UseIdentityAlwaysColumn();
|
||||
|
||||
// Type
|
||||
builder.Property(x => x.Type)
|
||||
.IsRequired();
|
||||
|
||||
// Title
|
||||
builder.Property(x => x.Title)
|
||||
.HasMaxLength(250)
|
||||
.IsRequired();
|
||||
|
||||
// Original title
|
||||
builder.Property(x => x.OriginalTitle)
|
||||
.HasMaxLength(250);
|
||||
|
||||
// Description
|
||||
builder.Property(x => x.Description)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
// Duration
|
||||
builder.Property(x => x.Duration);
|
||||
|
||||
// Release date
|
||||
builder.Property(x => x.ReleaseDate);
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
|
||||
|
||||
#region Navigation
|
||||
|
||||
// MediumGenre
|
||||
builder.HasMany(x => x.Genres)
|
||||
.WithMany(x => x.Media)
|
||||
.UsingEntity<MediumGenre>(
|
||||
x => x.HasOne(y => y.Genre)
|
||||
.WithMany(y => y.MediaRelationObjects)
|
||||
.HasForeignKey(y => y.GenreId)
|
||||
.IsRequired(),
|
||||
x => x.HasOne(y => y.Medium)
|
||||
.WithMany(y => y.GenresRelationshipObjects)
|
||||
.HasForeignKey(y => y.MediumId)
|
||||
.IsRequired()
|
||||
);
|
||||
|
||||
// MediumRating
|
||||
builder.HasMany(x => x.RatedBy)
|
||||
.WithMany(x => x.MediaRated)
|
||||
.UsingEntity<MediumRating>(
|
||||
x => x.HasOne(y => y.Account)
|
||||
.WithMany(y => y.MediaRatings)
|
||||
.HasForeignKey(y => y.AccountId)
|
||||
.IsRequired(),
|
||||
x => x.HasOne(y => y.Medium)
|
||||
.WithMany(y => y.Ratings)
|
||||
.HasForeignKey(y => y.MediumId)
|
||||
.IsRequired()
|
||||
);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Media;
|
||||
|
||||
public class MediumGenreConfiguration : IEntityTypeConfiguration<MediumGenre>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<MediumGenre> builder)
|
||||
{
|
||||
builder.ToTable("MediumGenres", "media");
|
||||
builder.HasKey(x => new { x.GenreId, x.MediumId });
|
||||
|
||||
// Medium
|
||||
// FK configured in MediumConfiguration
|
||||
builder.Property(x => x.MediumId)
|
||||
.IsRequired();
|
||||
|
||||
// Genre
|
||||
// FK configured in MediumConfiguration
|
||||
builder.Property(x => x.GenreId)
|
||||
.IsRequired();
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Media;
|
||||
|
||||
public class MediumMovieConfiguration : IEntityTypeConfiguration<MediumMovie>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<MediumMovie> builder)
|
||||
{
|
||||
// Budget
|
||||
builder.Property(x => x.Budget)
|
||||
.HasColumnType("money");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Media;
|
||||
|
||||
public class MediumPictureConfiguration : ImageEntityConfiguration<MediumPicture>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override void Configure(EntityTypeBuilder<MediumPicture> builder)
|
||||
{
|
||||
builder.ToTable("MediumPictures", "media");
|
||||
|
||||
// Medium
|
||||
builder.HasKey(x => x.MediumId);
|
||||
builder.HasIndex(x => x.MediumId)
|
||||
.IsUnique();
|
||||
builder.HasOne(x => x.Medium)
|
||||
.WithOne(x => x.Picture)
|
||||
.HasForeignKey<MediumPicture>(x => x.MediumId)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.MediumId)
|
||||
.IsRequired();
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
|
||||
// Generic properties
|
||||
base.Configure(builder);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Accounts;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Media;
|
||||
|
||||
public class MediumRatingConfiguration : RatingEntityConfiguration<MediumRating>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override void Configure(EntityTypeBuilder<MediumRating> builder)
|
||||
{
|
||||
builder.ToTable("MediumRatings", "media");
|
||||
builder.HasKey(x => new { x.AccountId, x.MediumId });
|
||||
|
||||
// Medium
|
||||
// FK configured in MediumConfiguration
|
||||
builder.Property(x => x.MediumId)
|
||||
.IsRequired();
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
|
||||
// Generic properties
|
||||
base.Configure(builder);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Media;
|
||||
|
||||
public class MediumSeriesConfiguration : IEntityTypeConfiguration<MediumSeries>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<MediumSeries> builder)
|
||||
{
|
||||
// Has ended
|
||||
builder.Property(x => x.HasEnded)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Media;
|
||||
|
||||
public class MediumViewCountConfiguration : ViewCountEntityConfiguration<MediumViewCount>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override void Configure(EntityTypeBuilder<MediumViewCount> builder)
|
||||
{
|
||||
builder.ToTable("MediumViewCounts", "media");
|
||||
builder.HasKey(x => new { x.MediumId, x.Date });
|
||||
|
||||
// Medium
|
||||
builder.HasOne(x => x.Medium)
|
||||
.WithMany(x => x.ViewCounts)
|
||||
.HasForeignKey(x => x.MediumId)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.MediumId)
|
||||
.IsRequired();
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
|
||||
// Generic properties
|
||||
base.Configure(builder);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user