Isolate OnModelCreating in Data classes (#1702)

This commit is contained in:
Nicolas Dorier
2020-06-27 21:55:16 +09:00
committed by GitHub
parent 72e407b69d
commit be44c3f9c2
14 changed files with 178 additions and 130 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace BTCPayServer.Data
{
@@ -29,5 +30,27 @@ namespace BTCPayServer.Data
get;
set;
}
internal static void OnModelCreating(ModelBuilder builder)
{
builder.Entity<UserStore>()
.HasOne(o => o.StoreData)
.WithMany(i => i.UserStores).OnDelete(DeleteBehavior.Cascade);
builder.Entity<UserStore>()
.HasKey(t => new
{
t.ApplicationUserId,
t.StoreDataId
});
builder.Entity<UserStore>()
.HasOne(pt => pt.ApplicationUser)
.WithMany(p => p.UserStores)
.HasForeignKey(pt => pt.ApplicationUserId);
builder.Entity<UserStore>()
.HasOne(pt => pt.StoreData)
.WithMany(t => t.UserStores)
.HasForeignKey(pt => pt.StoreDataId);
}
}
}