32 lines
1.0 KiB
C#
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);
|
|||
|
}
|
|||
|
}
|