-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Description
If I create an initial migration for the below context with 8.0.10, EntityId is created as nullable, even though it is marked as required, and the index is created with a NULL filter. If I rename it to XEntityId, it works as expected.
using System;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
await using var context = new MyContext();
await context.Database.MigrateAsync();
public class MyContext : DbContext
{
public DbSet<Entity> Entities { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.LogTo(Console.WriteLine)
.UseSqlServer("Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=Migrations;Integrated Security=SSPI");
}
[Index(nameof(EntityId), IsUnique = true)]
public class Entity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Key { get; set; }
[Required]
[MaxLength(50)]
public required string EntityId { get; set; }
}Reactions are currently unavailable