fix
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
namespace MyOffice.DbContext;
|
||||
|
||||
using Data.Models.Account;
|
||||
using Data.Models.Accounts;
|
||||
using Data.Models.Currencies;
|
||||
using Data.Models.Motions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Data.Models.Users;
|
||||
|
||||
@@ -29,6 +31,19 @@ public class AppDbContext : DbContext
|
||||
public DbSet<User> Users { get; set; } = null!;
|
||||
public DbSet<UserExternal> UserClaims { get; set; } = null!;
|
||||
|
||||
public DbSet<CurrencyGlobal> CurrencyGlobals { get; set; } = null!;
|
||||
public DbSet<Currency> Currencies { get; set; } = null!;
|
||||
public DbSet<CurrencyRate> CurrencyRates { get; set; } = null!;
|
||||
public DbSet<AccountCategory> AccountCategories { get; set; } = null!;
|
||||
public DbSet<Account> Accounts { get; set; } = null!;
|
||||
public DbSet<AccountAccountCategory> AccountAccountCategories { get; set; } = null!;
|
||||
public DbSet<AccountAccess> AccountAccesses { get; set; } = null!;
|
||||
|
||||
public DbSet<MotionGlobal> GlobalMotions { get; set; } = null!;
|
||||
public DbSet<MotionCategory> MotionCategories { get; set; } = null!;
|
||||
public DbSet<MotionAccount> Motions { get; set; } = null!;
|
||||
//public DbSet<AccountMotion> AccountMotions { get; set; } = null!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
var noCaseCollation = _noCaseCollation[_provider];
|
||||
@@ -59,12 +74,22 @@ public class AppDbContext : DbContext
|
||||
.WithMany(x => x.UserClaims)
|
||||
.HasForeignKey(x => x.UserId);
|
||||
|
||||
UserCreating(modelBuilder);
|
||||
CurrencyCreating(modelBuilder);
|
||||
AccountCreating(modelBuilder);
|
||||
MotionsCreating(modelBuilder);
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
private void UserCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<User>()
|
||||
.HasOne(x => x.Currency)
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.CurrencyId);
|
||||
}
|
||||
|
||||
private void CurrencyCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<CurrencyGlobal>()
|
||||
@@ -103,6 +128,12 @@ public class AppDbContext : DbContext
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<AccountCategory>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<AccountAccountCategory>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<Account>()
|
||||
.HasOne(x => x.CurrencyGlobal)
|
||||
.WithMany(x => x.Accounts)
|
||||
@@ -115,7 +146,64 @@ public class AppDbContext : DbContext
|
||||
|
||||
modelBuilder.Entity<AccountAccess>()
|
||||
.HasOne(x => x.User)
|
||||
.WithMany(x => x.AccessRights)
|
||||
.WithMany(x => x.AccountAccess)
|
||||
.HasForeignKey(x => x.UserId);
|
||||
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
.HasOne(x => x.Account)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.AccountId);
|
||||
|
||||
modelBuilder.Entity<AccountCategory>()
|
||||
.HasOne(x => x.User)
|
||||
.WithMany(x => x.AccountCategories)
|
||||
.HasForeignKey(x => x.UserId);
|
||||
|
||||
modelBuilder.Entity<AccountAccountCategory>()
|
||||
.HasOne(x => x.Account)
|
||||
.WithMany(x => x.Categories)
|
||||
.HasForeignKey(x => x.AccountId);
|
||||
|
||||
modelBuilder.Entity<AccountAccountCategory>()
|
||||
.HasOne(x => x.Category)
|
||||
.WithMany(x => x.Accounts)
|
||||
.HasForeignKey(x => x.CategoryId);
|
||||
}
|
||||
|
||||
private void MotionsCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<MotionGlobal>()
|
||||
.HasKey(x => x.Id);
|
||||
modelBuilder.Entity<MotionCategory>()
|
||||
.HasKey(x => x.Id);
|
||||
modelBuilder.Entity<MotionAccount>()
|
||||
.HasKey(x => x.Id);
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<MotionCategory>()
|
||||
.HasOne(x => x.User)
|
||||
.WithMany(x => x.MotionCategories)
|
||||
.HasForeignKey(x => x.UserId);
|
||||
|
||||
modelBuilder.Entity<MotionAccount>()
|
||||
.HasOne(x => x.Category)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.CategoryId);
|
||||
|
||||
modelBuilder.Entity<MotionAccount>()
|
||||
.HasOne(x => x.MotionGlobal)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.MotionGlobalId);
|
||||
|
||||
/*modelBuilder.Entity<AccountMotion>()
|
||||
.HasOne(x => x.Motion)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.MotionId);
|
||||
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
.HasOne(x => x.Account)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.AccountId);*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user