diff --git a/BTCPayServer.Data/Data/ApplicationDbContext.cs b/BTCPayServer.Data/Data/ApplicationDbContext.cs index 1de87caa7..0e18da7de 100644 --- a/BTCPayServer.Data/Data/ApplicationDbContext.cs +++ b/BTCPayServer.Data/Data/ApplicationDbContext.cs @@ -90,7 +90,8 @@ namespace BTCPayServer.Data PullPaymentData.OnModelCreating(builder); PayoutData.OnModelCreating(builder); RefundData.OnModelCreating(builder); - + U2FDevice.OnModelCreating(builder); + if (Database.IsSqlite() && !_designTime) { // SQLite does not have proper support for DateTimeOffset via Entity Framework Core, see the limitations diff --git a/BTCPayServer.Data/Data/U2FDevice.cs b/BTCPayServer.Data/Data/U2FDevice.cs index abf752310..57252f0e6 100644 --- a/BTCPayServer.Data/Data/U2FDevice.cs +++ b/BTCPayServer.Data/Data/U2FDevice.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; namespace BTCPayServer.Data { @@ -18,5 +19,15 @@ namespace BTCPayServer.Data public string ApplicationUserId { get; set; } public ApplicationUser ApplicationUser { get; set; } + + + internal static void OnModelCreating(ModelBuilder builder) + { + builder.Entity() + .HasOne(o => o.ApplicationUser) + .WithMany(i => i.U2FDevices) + .HasForeignKey(i => i.ApplicationUserId).OnDelete(DeleteBehavior.Cascade); + + } } }