34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using Heimdall.Domain.Entities;
|
|||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||
|
|
|
||
|
|
namespace Heimdall.Infrastructure.Data.Configurations;
|
||
|
|
|
||
|
|
public class UserCameraAccessConfiguration : IEntityTypeConfiguration<UserCameraAccess>
|
||
|
|
{
|
||
|
|
public void Configure(EntityTypeBuilder<UserCameraAccess> builder)
|
||
|
|
{
|
||
|
|
builder.ToTable("UserCameraAccesses");
|
||
|
|
|
||
|
|
builder.HasKey(eca => new { eca.UserId, eca.SiteId, eca.CameraId });
|
||
|
|
|
||
|
|
builder.HasOne(eca => eca.User)
|
||
|
|
.WithMany()
|
||
|
|
.HasForeignKey(eca => eca.UserId)
|
||
|
|
.OnDelete(DeleteBehavior.Cascade);
|
||
|
|
|
||
|
|
builder.HasOne(eca => eca.Site)
|
||
|
|
.WithMany()
|
||
|
|
.HasForeignKey(eca => eca.SiteId)
|
||
|
|
.OnDelete(DeleteBehavior.Cascade);
|
||
|
|
|
||
|
|
builder.HasOne(eca => eca.Camera)
|
||
|
|
.WithMany()
|
||
|
|
.HasForeignKey(eca => eca.CameraId)
|
||
|
|
.OnDelete(DeleteBehavior.Cascade)
|
||
|
|
.IsRequired(false);
|
||
|
|
|
||
|
|
// Query filter: exclude entries whose site was soft-deleted
|
||
|
|
builder.HasQueryFilter(eca => eca.Site == null || !eca.Site.IsDeleted);
|
||
|
|
}
|
||
|
|
}
|