Skip to content

AccidentalEntityType error generated on upgrade to EFCore 10 #37457

@smaglio81

Description

@smaglio81

Bug description

This error was generated after upgrading to EFCore 10.

System.InvalidOperationException : An error was generated for warning 'Microsoft.EntityFrameworkCore.Model.Validation.AccidentalEntityType': The type 'List<string>' has been mapped as an entity type. If you are mapping this type intentionally, then please suppress this warning and report the issue on GitHub. This exception can be suppressed or logged by passing event ID 'CoreEventId.AccidentalEntityType' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.

We followed the error message and suppressed CoreEventId.AccidentalEntityType.

I interpreted the line about If you are mapping this type intentionally, then please suppress this warning and report the issue on GitHub as saying that your team may not be sure how many customers this change will impact. And, that you wanted to have this issue reported on Github to gather feedback.

Following that logic, I'm not really reporting this to you as a bug, as much as reporting to you that it occurred.

Your code

IntegrationTest.cs

var dbContext = IntegrationTestsConfig.Services.GetService<SomeDbContext>();
using (dbContext)
{
   
	var result = dbContext.AreaPrograms.FirstOrDefault(); // error occurs on this line

	Assert.NotNull(result);
}


SomeDbContext.cs

public class SomeDbContext : OurBaseDbContext<SomeDbContext>
{
	public SomeDbContext(DbContextOptionsBuilder<SomeDbContext> builder) : base(builder)
	{ }

	public virtual DbSet<AreaProgram> AreaPrograms { get; set; }


AreaProgram.cs

public class AreaProgram
{

	public AreaProgram()
	{
		SubPrograms = new List<string>();
	}

	public int Id { get; set; }
	public string Area { get; set; }
	public string Program { get; set; }
	public List<string> SubPrograms { get; set; }
	public DateTime SystemUpdateDate { get; set; }
}


AreaProgramMapping.cs

public class AreaProgramMapping: IEntityTypeConfiguration<AreaProgram>
{
	public void Configure(EntityTypeBuilder<AreaProgram> builder)
	{
		builder.ToTable("Area_Program", "dbo");
		builder.HasKey(x => x.Id);
		builder.Ignore(x => x.SubPrograms);

Stack traces

EventDefinition`1.Log[TLoggerCategory](IDiagnosticsLogger`1 logger, TParam arg)
CoreLoggerExtensions.AccidentalEntityType(IDiagnosticsLogger`1 diagnostics, IEntityType entityType)
ModelValidator.ValidateEntityClrTypes(IModel model, IDiagnosticsLogger`1 logger)
ModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
SqlServerModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger)
ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger`1 validationLogger)
ModelSource.CreateModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
DbContextServices.CreateModel(Boolean designTime)
<39 more frames...>
DbContext.get_ContextServices()
DbContext.get_Model()
InternalDbSet`1.get_EntityType()
InternalDbSet`1.CheckState()
InternalDbSet`1.get_EntityQueryable()
IQueryable.get_Provider()
Queryable.FirstOrDefault[TSource](IQueryable`1 source)
CallDbTests.FirstOrDefault() line 21
MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Verbose output


EF Core version

10.0.1

Database provider

Microsoft.EntityFramework.SqlServer

Target framework

.NET 10

Operating system

Windows 11

IDE

Visual Studio 2026 - December 2025 Feature Update

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions