50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Application;
|
|
using Domain;
|
|
using Infrastructure.Identity;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Infrastructure
|
|
{
|
|
public class HNDbContext : IdentityDbContext<User, Role, Guid>, IData
|
|
{
|
|
public DbSet<Link> Links { get; set; }
|
|
public DbSet<Comment> Comments { get; set; }
|
|
|
|
IQueryable<Link> IData.Links => Links;
|
|
|
|
IQueryable<Comment> IData.Comments => Comments;
|
|
|
|
public HNDbContext() : base()
|
|
{
|
|
|
|
}
|
|
|
|
public HNDbContext(DbContextOptions<HNDbContext> options) : base(options)
|
|
{
|
|
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
// Soit
|
|
// modelBuilder.ApplyConfiguration(new LinkEntityType());
|
|
// modelBuilder.ApplyConfiguration(new CommentEntityType());
|
|
|
|
// Ou
|
|
modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly);
|
|
}
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
optionsBuilder.UseSqlite("Data Source=:memory:");
|
|
}
|
|
}
|
|
}
|
|
} |