using System.Reflection; using Core.Entities; using Microsoft.EntityFrameworkCore; namespace Infrastructure.Data { public class StoreContext : DbContext { public StoreContext(DbContextOptions options) : base(options) { } public DbSet Products { get; set; } public DbSet ProductBrands { get; set; } public DbSet ProductTypes { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); if(Database.ProviderName == "Microsoft.EntityFrameworkCore.Sqlite") { foreach (var entityType in modelBuilder.Model.GetEntityTypes()) { var properties = entityType.ClrType.GetProperties().Where(p => p.PropertyType == typeof(decimal)); foreach (var property in properties) { modelBuilder.Entity(entityType.Name).Property(property.Name).HasConversion(); } } } } } }