Skip to content

Leave out a DbContext's own members by type, not by name on every type - #566

Open
lukemurray wants to merge 1 commit into
mainfrom
fix/ignore-props-only-on-dbcontext
Open

lukemurray wants to merge 1 commit into
mainfrom
fix/ignore-props-only-on-dbcontext

Conversation

@lukemurray

Copy link
Copy Markdown
Collaborator

Problem

SchemaBuilderOptions.IgnoreProps defaulted to ["Database", "Model", "ChangeTracker", "ContextId"] to keep an EF Core DbContext's own members out of the schema. But ShouldIncludeMember checks it by name on every type. So an entity property called Model (a car's model, the model a request ran on) silently disappeared from the schema, with nothing to say why. The same went for Database, ChangeTracker and ContextId.

Change

  • The DbContext's members are left out by where they are declared. Any member declared on Microsoft.EntityFrameworkCore.DbContext is skipped. The match is on the type's full name, so EntityGraphQL still needs no reference to EF.
  • IgnoreProps is now empty by default. It still ignores any name added to it, on every type, as documented.

Behaviour change

A schema whose types have a property named Model, Database, ChangeTracker or ContextId now includes that field. To keep it out:

  • options.Builder.IgnoreProps.Add("Model"), or
  • [GraphQLIgnore] on the property.

Logged under a new 6.3.0 heading in the changelog; relabel if you'd rather.

Tests

  • EF: a DbContext schema has no root database, model, changeTracker or contextId field. This fails without the declaring-type check.
  • Core: an entity's Model and Database properties are fields. This fails with the old default list.
  • Core: IgnoreProps still ignores a name that's added to it.

Both suites pass on net10.0 (core 1208, EF 48).

Side note

.config/dotnet-tools.json lists the command as dotnet-csharpier, but CSharpier 1.0 renamed it to csharpier, so dotnet tool restore fails. That's not changed here. I formatted with dnx csharpier@1.0.0 and only kept formatting on the lines this PR changes.

🤖 Generated with Claude Code

IgnoreProps held Database, Model, ChangeTracker and ContextId by default, to keep an EF Core
DbContext's machinery out of the schema. It matches by name on every type, so any entity property
called Model (or Database, ...) was silently dropped from the schema too.

Members declared on Microsoft.EntityFrameworkCore.DbContext are now left out by their declaring
type, matched by name so there is still no EF reference, and IgnoreProps is empty by default. It
still ignores whatever names are added to it, everywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukemurray
lukemurray force-pushed the fix/ignore-props-only-on-dbcontext branch from e78a7ba to 7300671 Compare October 9, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant