36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using FinlyticTrades.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace FinlyticTrades.Database;
|
|
|
|
public class TradesDbContext : DbContext
|
|
{
|
|
public TradesDbContext(DbContextOptions<TradesDbContext> options) : base(options) { }
|
|
|
|
public DbSet<TradeEntity> Trades => Set<TradeEntity>();
|
|
public DbSet<TradeHourlyUpdateEntity> TradeHourlyUpdates => Set<TradeHourlyUpdateEntity>();
|
|
public DbSet<TradesSettingsEntity> Settings => Set<TradesSettingsEntity>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<TradeEntity>(entity =>
|
|
{
|
|
entity.HasIndex(e => e.TradeId).IsUnique();
|
|
entity.HasIndex(e => e.AnalysisId);
|
|
entity.HasIndex(e => e.EventId);
|
|
entity.HasIndex(e => e.Status);
|
|
entity.HasIndex(e => e.Sector);
|
|
entity.HasIndex(e => e.Isin);
|
|
entity.HasIndex(e => e.CreatedAt);
|
|
});
|
|
|
|
modelBuilder.Entity<TradeHourlyUpdateEntity>(entity =>
|
|
{
|
|
entity.HasIndex(e => e.TradeId);
|
|
entity.HasIndex(e => e.Timestamp);
|
|
});
|
|
}
|
|
}
|