46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using Database.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Pos;
|
|
|
|
|
|
namespace Database
|
|
{
|
|
public class PosDbContext : DbContext
|
|
{
|
|
|
|
public DbSet<EmployeeEntity> Employee { get; set; }
|
|
public DbSet<ProductGroupEntity> ProductGroups { get; set; }
|
|
public DbSet<ProductEntity> Products { get; set; }
|
|
public DbSet<SaleEntity> Sales { get; set; }
|
|
public DbSet<SaleLineEntity> SalesLines { get; set; }
|
|
public DbSet<PaymentEntity> Payment { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<SaleLineEntity>()
|
|
.Property(saleLine => saleLine.Pieces)
|
|
.HasConversion<short>()
|
|
.HasColumnType("smallint");
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
}
|
|
|
|
protected override void OnConfiguring(
|
|
DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
LoadConfig l = new LoadConfig();
|
|
IConfiguration config = l.ByEnvironment();
|
|
string connectionString = config["SqlServer"].ToString();
|
|
optionsBuilder
|
|
.UseSqlServer(connectionString)
|
|
.UseLoggerFactory(LoggerFactory.Create(b => b
|
|
.AddFilter(level => level >= LogLevel.Information)))
|
|
.EnableSensitiveDataLogging()
|
|
.EnableDetailedErrors();
|
|
base.OnConfiguring(optionsBuilder);
|
|
}
|
|
}
|
|
}
|