Files
WatchIt/WatchIt.Database/WatchIt.Database.Model/Person/Person.cs

82 lines
2.3 KiB
C#
Raw Normal View History

2024-03-20 00:34:47 +01:00
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WatchIt.Database.Model.Account;
2024-03-21 18:33:34 +01:00
using WatchIt.Database.Model.Common;
using WatchIt.Database.Model.ViewCount;
2024-03-20 00:34:47 +01:00
namespace WatchIt.Database.Model.Person
{
public class Person : IEntity<Person>
{
#region PROPERTIES
public long Id { get; set; }
public string Name { get; set; }
public string? FullName { get; set; }
public string? Description { get; set; }
public DateOnly? BirthDate { get; set; }
public DateOnly? DeathDate { get; set; }
2024-03-21 18:33:34 +01:00
public short GenderId { get; set; }
2024-03-20 00:34:47 +01:00
public Guid? PersonPhotoId { get; set; }
#endregion
#region NAVIGATION
2024-03-21 18:33:34 +01:00
public Gender Gender { get; set; }
2024-03-20 00:34:47 +01:00
public PersonPhotoImage? PersonPhoto { get; set; }
public IEnumerable<PersonActorRole> PersonActorRoles { get; set; }
public IEnumerable<PersonCreatorRole> PersonCreatorRoles { get; set; }
2024-03-21 18:33:34 +01:00
public IEnumerable<ViewCountPerson> ViewCountsPerson { get; set; }
2024-03-20 00:34:47 +01:00
#endregion
#region PUBLIC METHODS
static void IEntity<Person>.Build(EntityTypeBuilder<Person> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Id)
.IsUnique();
builder.Property(x => x.Id)
.IsRequired();
builder.Property(x => x.Name)
.HasMaxLength(100)
.IsRequired();
builder.Property(x => x.FullName)
.HasMaxLength(200);
builder.Property(x => x.Description)
.HasMaxLength(1000);
builder.Property(x => x.BirthDate);
builder.Property(x => x.DeathDate);
2024-03-21 18:33:34 +01:00
builder.HasOne(x => x.Gender)
.WithMany()
.HasForeignKey(x => x.GenderId)
.IsRequired();
builder.Property(x => x.GenderId)
.IsRequired();
2024-03-20 00:34:47 +01:00
builder.HasOne(x => x.PersonPhoto)
.WithOne(x => x.Person)
.HasForeignKey<Person>(e => e.PersonPhotoId);
builder.Property(x => x.PersonPhotoId);
}
#endregion
}
}