41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WpfApp1TRC20.Data
|
|
{
|
|
public class AppDbContext : DbContext
|
|
{
|
|
public DbSet<TokenInfo> Tokens { get; set; }
|
|
public DbSet<WalletAccount> Wallets { get; set; }
|
|
public DbSet<TransactionRecord> Transactions { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
var dbPath = Path.Combine(appDataPath, "TRC20TokenManager", "app.db");
|
|
Directory.CreateDirectory(Path.GetDirectoryName(dbPath));
|
|
optionsBuilder.UseSqlite($"Data Source={dbPath}");
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<TokenInfo>()
|
|
.Property(e => e.TotalSupply)
|
|
.HasConversion<string>();
|
|
|
|
modelBuilder.Entity<TransactionRecord>()
|
|
.Property(e => e.Amount)
|
|
.HasConversion<string>();
|
|
|
|
modelBuilder.Entity<WalletAccount>()
|
|
.Property(e => e.TrxBalance)
|
|
.HasConversion<string>();
|
|
}
|
|
}
|
|
}
|