using HackerNet.Application; using HackerNet.Domain; using HackerNet.Infrastructure.Repositories.EntityFramework.EntityTypeConfigurations; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace HackerNet.Infrastructure.Repositories.EntityFramework; public class HackerContext : IdentityDbContext { #pragma warning disable CS8618 public DbSet Links { get; set; } public DbSet Comments { get; set; } #pragma warning restore CS8618 public HackerContext() : base() { } public HackerContext(DbContextOptions options) : base(options) { } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { optionsBuilder.UseSqlite("Data Source=:memory:"); } } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // var link = modelBuilder.Entity(); // link.HasKey(o => o.Id); // link.Property(o => o.Url).IsRequired().HasMaxLength(250); // link.Property(o => o.Description).IsRequired(); // link.Property(o => o.CreatedAt).IsRequired(); // var comment = modelBuilder.Entity(); // comment.HasKey(o => o.Id); // comment.HasOne() // .WithMany() // .HasForeignKey(o => o.LinkId) // .IsRequired() // .OnDelete(DeleteBehavior.Cascade); // comment.Property(o => o.Content).IsRequired(); // comment.Property(o => o.CreatedAt).IsRequired(); //modelBuilder.ApplyConfiguration(new LinkEntityTypeConfiguration()); //modelBuilder.ApplyConfiguration(new CommentEntityTypeConfiguration()); modelBuilder.ApplyConfigurationsFromAssembly(typeof(HackerContext).Assembly); } }