GGMM/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs
MarcEricMartel 7ce0e7a83f Début API
2022-10-08 10:22:12 -07:00

32 lines
1.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using GrossesMitainesAPI.Models;
namespace GrossesMitainesAPI.Data;
public class InventoryContext : DbContext {
public DbSet<Product> Products { get; set; }
public InventoryContext(DbContextOptions<InventoryContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
// Pour partir la BD.
modelBuilder.Entity<Product>().HasData(new Product {
Id = 1,
Title = $"",
Description = $"",
Price = 0.00M,
ImageData = $""
});
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var connectionString = configuration.GetConnectionString("DefaultConnection");
optionsBuilder.UseSqlServer(connectionString);
}
}