diff --git a/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs b/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs index e9bd3af278..9b6549663c 100644 --- a/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs +++ b/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs @@ -163,7 +163,6 @@ public class DatabaseContext : DbContext } eCipher.ToTable(nameof(Cipher)); - eCipherArchive.ToTable(nameof(CipherArchive)); eCollection.ToTable(nameof(Collection)); eCollectionCipher.ToTable(nameof(CollectionCipher)); eEmergencyAccess.ToTable(nameof(EmergencyAccess)); diff --git a/src/Infrastructure.EntityFramework/Vault/Configurations/CipherArchiveConfigurations.cs b/src/Infrastructure.EntityFramework/Vault/Configurations/CipherArchiveConfigurations.cs index 50db798353..ff6c64cd43 100644 --- a/src/Infrastructure.EntityFramework/Vault/Configurations/CipherArchiveConfigurations.cs +++ b/src/Infrastructure.EntityFramework/Vault/Configurations/CipherArchiveConfigurations.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using Bit.Infrastructure.EntityFramework.Vault.Models; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Bit.Infrastructure.EntityFramework.Vault.Configurations; @@ -17,7 +18,12 @@ public class CipherArchiveConfiguration : IEntityTypeConfiguration ca.CipherId) .OnDelete(DeleteBehavior.Cascade); - // If you want explicit mapping: + builder + .HasOne(ca => ca.User) + .WithMany() + .HasForeignKey(ca => ca.UserId) + .OnDelete(DeleteBehavior.Cascade); + builder.Property(ca => ca.ArchivedDate).IsRequired(); } } diff --git a/src/Infrastructure.EntityFramework/Vault/Models/CipherArchive.cs b/src/Infrastructure.EntityFramework/Vault/Models/CipherArchive.cs index 1b3baf0d3d..51c52ac6d5 100644 --- a/src/Infrastructure.EntityFramework/Vault/Models/CipherArchive.cs +++ b/src/Infrastructure.EntityFramework/Vault/Models/CipherArchive.cs @@ -1,6 +1,8 @@ #nullable disable -using Bit.Infrastructure.EntityFramework.Vault.Models; +using Bit.Infrastructure.EntityFramework.Models; + +namespace Bit.Infrastructure.EntityFramework.Vault.Models; public class CipherArchive { @@ -8,6 +10,7 @@ public class CipherArchive public Guid UserId { get; set; } public DateTime ArchivedDate { get; set; } - // Optional navigation props – you can drop these if you don't want them. + // Navigation props public Cipher Cipher { get; set; } + public User User { get; set; } // optional, matches FK }