using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using BTCPayServer.Models; using Microsoft.EntityFrameworkCore.Infrastructure.Internal; using Microsoft.EntityFrameworkCore.Infrastructure; namespace BTCPayServer.Data { public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext() { } public ApplicationDbContext(DbContextOptions options) : base(options) { } public DbSet Invoices { get; set; } public DbSet InvoiceEvents { get; set; } public DbSet HistoricalAddressInvoices { get; set; } public DbSet PendingInvoices { get; set; } public DbSet RefundAddresses { get; set; } public DbSet Payments { get; set; } public DbSet Stores { get; set; } public DbSet UserStore { get; set; } public DbSet AddressInvoices { get; set; } public DbSet Settings { get; set; } public DbSet PairingCodes { get; set; } public DbSet PairedSINData { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var isConfigured = optionsBuilder.Options.Extensions.OfType().Any(); if (!isConfigured) optionsBuilder.UseSqlite("Data Source=temp.db"); } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity() .HasIndex(o => o.StoreDataId); builder.Entity() .HasIndex(o => o.InvoiceDataId); builder.Entity() .HasIndex(o => o.InvoiceDataId); builder.Entity() .HasKey(t => new { t.ApplicationUserId, t.StoreDataId }); builder.Entity() .HasOne(pt => pt.ApplicationUser) .WithMany(p => p.UserStores) .HasForeignKey(pt => pt.ApplicationUserId); builder.Entity() .HasOne(pt => pt.StoreData) .WithMany(t => t.UserStores) .HasForeignKey(pt => pt.StoreDataId); builder.Entity() #pragma warning disable CS0618 .HasKey(o => o.Address); #pragma warning restore CS0618 builder.Entity() .HasKey(o => o.Id); builder.Entity(b => { b.HasIndex(o => o.SIN); b.HasIndex(o => o.StoreDataId); }); builder.Entity() .HasKey(o => new { o.InvoiceDataId, #pragma warning disable CS0618 o.Address #pragma warning restore CS0618 }); builder.Entity() .HasKey(o => new { o.InvoiceDataId, #pragma warning disable CS0618 o.UniqueId #pragma warning restore CS0618 }); } } }