You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EFCore.Jet.Integration.Test.Model28
|
|
{
|
|
public class Context : DbContext
|
|
{
|
|
|
|
public Context(DbContextOptions options) : base (options)
|
|
{
|
|
}
|
|
|
|
public DbSet<Advertisement> Advertisements { get; set; }
|
|
public DbSet<User> Users { get; set; }
|
|
public DbSet<AdImage> AdImages { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<User>()
|
|
.HasMany(u => u.Advertisements)
|
|
.WithOne(x => x.User)
|
|
.IsRequired()
|
|
;
|
|
|
|
modelBuilder.Entity<Advertisement>()
|
|
.HasMany(a => a.AdImages)
|
|
.WithOne(x => x.Advertisement)
|
|
.IsRequired()
|
|
;
|
|
|
|
// Is required must be inserted in foreign key field if there is one
|
|
/*
|
|
modelBuilder.Entity<AdImage>()
|
|
.Property(x => x.Advertisement)
|
|
.IsRequired()
|
|
;
|
|
*/
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
}
|
|
}
|
|
}
|