28 lines
847 B
C#
28 lines
847 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using SequenceAuth.Example.Domain;
|
|
|
|
namespace SequenceAuth.Example.Infrastructure;
|
|
|
|
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
|
|
{
|
|
public DbSet<User> Users => Set<User>();
|
|
public DbSet<TodoItem> Todos => Set<TodoItem>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<User>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.Property(e => e.Username).IsRequired();
|
|
entity.HasIndex(e => e.Username).IsUnique();
|
|
});
|
|
|
|
modelBuilder.Entity<TodoItem>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.Property(e => e.Title).IsRequired();
|
|
entity.Property(e => e.Status).HasConversion<string>();
|
|
});
|
|
}
|
|
}
|