49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using Entities.Contracts;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace TechHelper.Context.Configuration
|
|
{
|
|
public class AssignmentAttachmentConfiguration : IEntityTypeConfiguration<AssignmentAttachment>
|
|
{
|
|
public void Configure(EntityTypeBuilder<AssignmentAttachment> builder)
|
|
{
|
|
builder.ToTable("assignment_attachments");
|
|
|
|
builder.HasKey(aa => aa.Id);
|
|
|
|
builder.Property(aa => aa.Id)
|
|
.HasColumnName("id");
|
|
|
|
builder.Property(aa => aa.AssignmentId)
|
|
.HasColumnName("assignment_id")
|
|
.IsRequired();
|
|
|
|
builder.Property(aa => aa.FilePath)
|
|
.HasColumnName("file_path")
|
|
.IsRequired()
|
|
.HasMaxLength(255);
|
|
|
|
builder.Property(aa => aa.FileName)
|
|
.HasColumnName("file_name")
|
|
.IsRequired()
|
|
.HasMaxLength(255);
|
|
|
|
builder.Property(aa => aa.UploadedAt)
|
|
.HasColumnName("uploaded_at")
|
|
.ValueGeneratedOnAdd(); // Set value on creation
|
|
|
|
builder.Property(aa => aa.IsDeleted)
|
|
.HasColumnName("deleted")
|
|
.HasDefaultValue(false);
|
|
|
|
// Configure the relationship explicitly
|
|
builder.HasOne(aa => aa.Assignment) // An AssignmentAttachment has one Assignment
|
|
.WithMany(a => a.AssignmentAttachments) // An Assignment has many AssignmentAttachments (assuming 'Attachments' collection in Assignment)
|
|
.HasForeignKey(aa => aa.AssignmentId) // The foreign key is AssignmentAttachment.AssignmentId
|
|
.IsRequired() // It's a required relationship based on your [Required] attribute
|
|
.OnDelete(DeleteBehavior.Cascade); // If an Assignment is deleted, its attachments should also be deleted
|
|
}
|
|
}
|
|
}
|