Skip to content

fix(xpo): XpoDatabase creates only the tables of its own data layer - #25

Merged
donwibier merged 1 commit into
masterfrom
fix/xpo-schema-per-data-layer
Nov 18, 2026
Merged

donwibier merged 1 commit into
masterfrom
fix/xpo-schema-per-data-layer

Conversation

@donwibier

Copy link
Copy Markdown
Owner

Problem

With UpdateSchema = AutoCreateOption.DatabaseAndSchema, XpoDatabase.CreateDataLayer ran session.UpdateSchema() on a SimpleDataLayer created without a dictionary. That uses XPO's process-wide default dictionary with every persistent class of every loaded assembly, so:

  • classes that [XpoDataLayer("other")] assigns to another data layer got a table in every database (the data layer's own dictionary was filtered, the schema update was not);
  • with two copies of an assembly loaded in separate AssemblyLoadContexts (plugins), it threw Dictionary already contains ClassInfo …, also for data layers that never use those classes;
  • it added classes to XpoDefault's dictionary as a side effect.

Found in DX.Cms: a plugin's XPO classes ended up in the content database, and test hosts that load a plugin more than once failed.

Fix

The schema update uses a dictionary of its own, with the classes XPO collects per assembly (CollectClassInfos, one throwaway dictionary per assembly so duplicate copies do not clash), minus the classes of other data layers. Only persistent class infos go to UpdateSchema / CreateObjectTypeRecords.

Behaviour kept: classes without [XpoDataLayer], with or without [Persistent], still get their tables in every data layer (PlainXPObjectWithoutPersistentAttribute_IsUsable). Tables that older versions created for other data layers stay in existing databases.

Version: DX.Data.Xpo 26.1.3.42, with release notes in the csproj, DX.Data.Xpo/README.md and the root README.

Tests

  • New: UpdateSchema_CreatesTheTablesOfItsOwnDataLayerOnly, UpdateSchema_CreatesTheTablesOfClassesAssignedToIt (OtherLayerNote with [XpoDataLayer]).
  • DX.Data.Xpo.Tests 171/171 and DX.Data.Xpo.Identity.Tests 250/250 on net8.0 and net10.0; DX.Data.Xpo builds for net462. Not run on net9.0 (no runtime on the build machine).
  • Checked downstream: DX.Cms on a local build of this package, 582/582 tests including its data contract tests on SQL Server 2022.

🤖 Generated with Claude Code

The schema update (UpdateSchema = DatabaseAndSchema) ran session.UpdateSchema()
on a SimpleDataLayer without a dictionary: XPO's process-wide default dictionary
with every persistent class of every loaded assembly. Classes that
[XpoDataLayer("other")] assigns to another data layer got a table in every
database, and two copies of an assembly in separate load contexts (plugins) made
it throw "Dictionary already contains ClassInfo".

It now uses a dictionary of its own with the classes XPO collects per assembly,
minus those of other data layers. Classes without [XpoDataLayer] (with or without
[Persistent]) still get their tables, as before. Version 26.1.3.42.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@donwibier
donwibier merged commit 8adf8a9 into master Nov 18, 2026
2 checks passed
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