Implement initial product management with Entity Framework Core #3

This commit is contained in:
Marek Lesko
2025-07-27 16:03:55 +00:00
parent 5f921e5a2c
commit e969008873
9 changed files with 272 additions and 22 deletions

View File

@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
namespace Api.Models
{
public class Product
{
public int Id { get; set; }
public string? Name { get; set; }
public decimal Price { get; set; }
}
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public DbSet<Product> Products { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Seed data
modelBuilder.Entity<Product>().HasData(
new Product { Id = 1, Name = "Sample Product", Price = 9.99M }
);
}
}
}