First table in database
This commit is contained in:
@@ -1,12 +1,27 @@
|
||||
using GerbilManagerWebAPI.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
public class ApplicationContext : DbContext
|
||||
{
|
||||
public ApplicationContext(DbContextOptions options)
|
||||
:base(options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
public DbSet<Gerbil> Gerbils { get; set; }
|
||||
public DbSet<Litter> Litters { get; set; }
|
||||
public DbSet<Breeder> Breeders { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Gerbil>().HasOne(entity => entity.Litter);
|
||||
modelBuilder.Entity<Litter>().HasOne(entity => entity.Father);
|
||||
modelBuilder.Entity<Litter>().HasOne(entity => entity.Mother);
|
||||
|
||||
modelBuilder
|
||||
.Entity<Gerbil>()
|
||||
.Property(d => d.Gender)
|
||||
.HasConversion(new EnumToStringConverter<Gender>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user