Refactoring, database structure changed
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
70
WatchIt.Database/Configuration/Roles/RoleConfiguration.cs
Normal file
70
WatchIt.Database/Configuration/Roles/RoleConfiguration.cs
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user