text: Q:
  
  Entity Framework Core - Fluent API not configuring model
  
  I've been trying to get the fluent API working to configure my model. I can't find what's wrong.
  It does not seems to enforce any of the constraints but I can see the code run when the model is created. The Documentation says that the Fluent API will override any previous annotations i.e take priority.
  Things are working when I use Data annotations in the model.
  Here is a simplified example of code that works (In Model - Data annotation) vs one that doesn't (In Context - OnModelCreating).
  //In Model
  using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Text.Json.Serialization;
  
  namespace ParkingPermitData.Models
  {
  
      public class PermitPurchase
      {
          public int PermitPurchaseId { get; set; }
          [Required]
          public string ParkingPermitNumber { get; set; }
          public string PurchaserName { get; set; }
      }
  }
  
  //In Context
  using Microsoft.EntityFrameworkCore;
  using ParkingPermitData.Models;
  namespace ParkingPermitData.Data
  {
      public class ParkingPermitContext : DbContext
      {
          public ParkingPermitContext(DbContextOptions<ParkingPermitContext> options) : base(options)
          {
          }
  
          public DbSet<PermitPurchase> PermitPurchases { get; set; }
  
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
              modelBuilder.Entity<PermitPurchase>().ToTable("PermitPurchase");
  
              modelBuilder.Entity<PermitPurchase>()
                  .Property(b => b.ParkingPermitNumber)
                  .IsRequired();
  
          }
      }
  }
  
  I have tried the code in OnModelCreating as a single statement along with many other variations of this which I have found in examples.
  I was trying to setup some more complex relationships and annotations than this but wondered why they weren't working, then tried this very simple case.
  It's very frustrating and I would appreciate any help with this please.
  One thing to note is i'm using the InMemoryDatabase for the DBContext in early development.
  //Startup
  public void ConfigureServices(IServiceCollection services)
  {
      services.AddDbContext<ParkingPermitContext>(opt =>
                              opt.UseInMemoryDatabase("ParkingPermitPurchases"));
      services.AddControllers();
  }
  
  Many thanks,
  Paul
  
  A:
  
  In memory database disregards db constraints as it is not a relation database. In particular 
  
  InMemory will allow you to save data that would violate referential integrity constraints in a relational database.
  
  See documentation
  for more information on what is supported
  
  