30 lines
851 B
C#
30 lines
851 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using StockHistory.Models;
|
|
|
|
namespace StockHistory.Data;
|
|
|
|
public class AppDbContext : DbContext
|
|
{
|
|
public AppDbContext(DbContextOptions<AppDbContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public DbSet<TransactionNote> TransactionNotes { get; set; }
|
|
public DbSet<StockEquity> Stocks { get; set; }
|
|
|
|
override protected void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
modelBuilder.Entity<TransactionNote>()
|
|
.HasIndex(t => new { t.StockCode, t.TransactionDate })
|
|
.IsUnique(true);
|
|
modelBuilder.Entity<StockEquity>()
|
|
.HasIndex(s => new { s.Bought })
|
|
.IsUnique(false);
|
|
modelBuilder.Entity<StockEquity>()
|
|
.HasIndex(s => new { s.Sold })
|
|
.IsUnique(false);
|
|
}
|
|
}
|