Refactoring, database structure changed
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Converters;
|
||||
using WatchIt.Database.Model.Photos;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Photos;
|
||||
|
||||
public class PhotoBackgroundConfiguration : IEntityTypeConfiguration<PhotoBackground>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<PhotoBackground> builder)
|
||||
{
|
||||
builder.ToTable("PhotoBackground", "photos");
|
||||
|
||||
// Id
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.HasIndex(x => x.Id)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.Id)
|
||||
.IsRequired();
|
||||
|
||||
// Photo
|
||||
builder.HasOne(x => x.Photo)
|
||||
.WithOne(x => x.Background)
|
||||
.HasForeignKey<PhotoBackground>(x => x.PhotoId)
|
||||
.IsRequired();
|
||||
builder.HasIndex(x => x.PhotoId)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.PhotoId)
|
||||
.IsRequired();
|
||||
|
||||
// Is universal
|
||||
builder.Property(x => x.IsUniversal)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
// First gradient color
|
||||
builder.Property(x => x.FirstGradientColor)
|
||||
.HasConversion<ColorToByteArrayConverter>()
|
||||
.IsRequired();
|
||||
|
||||
// Second gradient color
|
||||
builder.Property(x => x.SecondGradientColor)
|
||||
.HasConversion<ColorToByteArrayConverter>()
|
||||
.IsRequired();
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user