Hello,
this is how your DbContext should be
public class YourDbContext : DbContext
{
public virtual DbSet<Owner> Owners { get; set; }
public virtual DbSet<Car> Cars { get; set; }
public virtual DbSet<Image> Images { get; set; }
public YourDbContext(DbContextOptions<YourDbContext> context)
: base(context)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Owner>(o =>
{
o.ToTable("Owners");
o.HasMany(owner => owner.Cars)
.WithOne(car => car.Owner)
.HasForeignKey(car => car.OwnerId);
});
modelBuilder.Entity<Car>(c =>
{
c.ToTable("Cars");
c.HasMany(car => car.Images)
.WithOne(image => image.Car)
.HasForeignKey(image => image.CarId);
});
modelBuilder.Entity<Image>(i =>
{
i.ToTable("Images");
});
}
}