Refactoring, database structure changed

This commit is contained in:
2025-03-03 00:56:32 +01:00
Unverified
parent d3805ef3db
commit c603c41c0b
913 changed files with 21764 additions and 32775 deletions

View File

@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleActorConfiguration : IEntityTypeConfiguration<RoleActor>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<RoleActor> builder)
{
// Actor type
builder.HasOne(x => x.ActorType)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.ActorTypeId)
.IsRequired();
builder.Property(x => x.ActorTypeId)
.IsRequired();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
}
#endregion
}

View File

@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleActorTypeConfiguration : IEntityTypeConfiguration<RoleActorType>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<RoleActorType> builder)
{
builder.ToTable("RoleActorTypes", "roles");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired()
.UseIdentityAlwaysColumn();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,70 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleConfiguration : IEntityTypeConfiguration<Role>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<Role> builder)
{
builder.ToTable("Roles", "roles");
builder.HasDiscriminator<RoleType>("Type")
.HasValue<RoleActor>(RoleType.Actor)
.HasValue<RoleCreator>(RoleType.Creator);
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
// Type
builder.Property(x => x.Type)
.IsRequired();
// Medium
builder.HasOne(x => x.Medium)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.MediumId)
.IsRequired();
builder.Property(x => x.MediumId)
.IsRequired();
// Person
builder.HasOne(x => x.Person)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.PersonId)
.IsRequired();
builder.Property(x => x.PersonId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
#region Navigation
// RoleRating
builder.HasMany(x => x.RatedBy)
.WithMany(x => x.RolesRated)
.UsingEntity<RoleRating>(
x => x.HasOne(y => y.Account)
.WithMany(y => y.RolesRatings)
.HasForeignKey(y => y.AccountId)
.IsRequired(),
x => x.HasOne(y => y.Role)
.WithMany(y => y.Ratings)
.HasForeignKey(y => y.RoleId)
.IsRequired()
);
#endregion
}
#endregion
}

View File

@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleCreatorConfiguration : IEntityTypeConfiguration<RoleCreator>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<RoleCreator> builder)
{
// Creator type
builder.HasOne(x => x.CreatorType)
.WithMany(x => x.Roles)
.HasForeignKey(x => x.CreatorTypeId)
.IsRequired();
builder.Property(x => x.CreatorTypeId)
.IsRequired();
}
#endregion
}

View File

@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleCreatorTypeConfiguration : IEntityTypeConfiguration<RoleCreatorType>
{
#region PUBLIC METHODS
public void Configure(EntityTypeBuilder<RoleCreatorType> builder)
{
builder.ToTable("RoleCreatorTypes", "roles");
// Id
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired()
.UseIdentityAlwaysColumn();
// Name
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
}
#endregion
}

View File

@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WatchIt.Database.Model.Roles;
namespace WatchIt.Database.Configuration.Roles;
public class RoleRatingConfiguration : RatingEntityConfiguration<RoleRating>
{
#region PUBLIC METHODS
public override void Configure(EntityTypeBuilder<RoleRating> builder)
{
builder.ToTable("RoleRatings", "roles");
builder.HasKey(x => new { x.AccountId, x.RoleId });
// Role
// FK configured in RoleConfiguration
builder.Property(x => x.RoleId)
.IsRequired();
// Version
builder.Property(b => b.Version)
.IsRowVersion();
// Generic properties
base.Configure(builder);
}
#endregion
}