2022-08-04 03:59:04 +03:00
|
|
|
using System;
|
|
|
|
using BlueWest.Data;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
2022-08-18 22:59:13 +03:00
|
|
|
namespace BlueWest.WebApi.MySQL
|
2022-08-04 03:59:04 +03:00
|
|
|
{
|
2022-08-13 06:35:36 +03:00
|
|
|
|
2022-08-18 22:59:13 +03:00
|
|
|
public sealed class UserDbContext : DbContext
|
|
|
|
{
|
|
|
|
public DbSet<User> Users { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public IConfiguration Configuration;
|
2022-08-04 03:59:04 +03:00
|
|
|
|
|
|
|
|
2022-08-18 22:59:13 +03:00
|
|
|
public UserDbContext(DbContextOptions<UserDbContext> options) : base(options)
|
|
|
|
{
|
|
|
|
Database.EnsureCreated();
|
2022-08-04 03:59:04 +03:00
|
|
|
|
2022-08-18 22:59:13 +03:00
|
|
|
}
|
2022-08-04 03:59:04 +03:00
|
|
|
|
2022-08-18 22:59:13 +03:00
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
{
|
|
|
|
/*optionsBuilder.UseMySql(
|
|
|
|
Configuration.GetConnectionString("LocalMySQL"),
|
|
|
|
new MySqlServerVersion(new Version(8, 0, 11))
|
|
|
|
);*/
|
|
|
|
}
|
2022-08-04 03:59:04 +03:00
|
|
|
|
2022-08-18 22:59:13 +03:00
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
2022-08-04 03:59:04 +03:00
|
|
|
{
|
2022-08-18 22:59:13 +03:00
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
|
|
|
|
modelBuilder.Entity<User>(builder =>
|
|
|
|
{
|
|
|
|
builder.HasKey(x => x.Id);
|
|
|
|
});
|
2022-08-04 03:59:04 +03:00
|
|
|
|
2022-08-18 22:59:13 +03:00
|
|
|
modelBuilder.Entity<FinanceOp>(builder =>
|
|
|
|
{
|
|
|
|
builder.HasOne<User>()
|
|
|
|
.WithMany(x => x.FinanceTransactions)
|
|
|
|
.HasForeignKey(x => x.UserId);
|
|
|
|
});
|
2022-08-04 03:59:04 +03:00
|
|
|
|
2022-08-13 06:35:36 +03:00
|
|
|
|
|
|
|
|
2022-08-18 22:59:13 +03:00
|
|
|
}
|
2022-08-04 03:59:04 +03:00
|
|
|
}
|
2022-08-18 22:59:13 +03:00
|
|
|
}
|