Project/Project.Infrastructure/ApplicationDbContext.cs
2024-07-10 09:00:36 +02:00

30 lines
858 B
C#

using Microsoft.EntityFrameworkCore;
using Project.Domain.Entities;
namespace Project.Infrastructure
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<User> Users { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<CategoryRole> CategoriesRoles { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<User>()
.HasOne(u => u.Role)
.WithMany()
.HasForeignKey(u => u.RoleId);
}
}
}