Repository navigation
XpoDatabaseOptions.SetAsXpoDefault, and a strict ParseEnum overload - #24
Merged
Merged
Conversation
….DataLayer XpoDatabase set the process-wide XpoDefault.DataLayer as a side effect, but only when UpdateSchema was DatabaseAndSchema (typical in development, rare in production) and then to whichever database was created last, as a separate data layer over the same store. That contradicted XpoDatabase setting XpoDefault.Session to null to prevent accidental use of the defaults. The new SetAsXpoDefault option (default false) sets XpoDefault.DataLayer to the database's own data layer, whatever the schema option. Behaviour change (documented in the READMEs and release notes): code that creates sessions without a data layer (new UnitOfWork(), new Session(), XPCollection without a session) must set SetAsXpoDefault = true on the database it should use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ParseEnum(value, defaultValue, definedOnly, ignoreCase = false): with definedOnly, a value must be a member of the enum or, for a [Flags] enum, a combination of its flags; anything else returns the default. The existing overloads keep following Enum.TryParse. Also IsDefinedEnumValue(value), and the root README section for this follow-up release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s instead of failing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves the two behaviours that #23 left pinned as skipped "BY DESIGN?" tests. No tests are skipped any more.
XpoDatabaseandXpoDefault.DataLayer(DX.Data.Xpo 26.1.3.41)XpoDatabaseused to set the process-wideXpoDefault.DataLayeras a side effect. That had several problems:UpdateSchemawasDatabaseAndSchema, which is typical in development and rare in production. Code relying on it worked in dev and broke in production.XpoDatabasehands out. It was a separateThreadSafeDataLayerover the same store.XpoDatabasesetsXpoDefault.Session = nullto prevent accidental use of XPO's defaults.This PR removes the implicit assignment and adds
XpoDatabaseOptions.SetAsXpoDefault(defaultfalse). When set,XpoDefault.DataLayerbecomes that database's own data layer, whatever the schema option. Nothing in this repo relies on the global.Behaviour change: code that creates sessions without a data layer (
new UnitOfWork(),new Session(), anXPCollectionwithout a session) must now setSetAsXpoDefault = true. This is documented in the root README, the DX.Data.Xpo README and the release notes.Tests:
Ctor_DoesNotReplaceXpoDefaultDataLayernow runs and passes.SchemaAlreadyExists;ParseEnum(DX.Utils 26.1.3.42)The existing overloads are unchanged. They follow
Enum.TryParse, so"99"still gives(TEnum)99, as the docs promise; only conversion errors return the default.This PR adds an opt-in overload,
ParseEnum(value, defaultValue, definedOnly, ignoreCase = false):definedOnly, a value must be one of the enum's members.[Flags]enum, any combination of its flags is accepted.ulong.IsDefinedEnumValue(value)is also exposed. The skipped test is replaced by one pinning today's behaviour, plus tests for strict mode ([Flags],ignoreCase, andulong/sbyteunderlying types).Versions
Each is one above what's on NuGet now. The commits deliberately avoid a "BREAKING CHANGE" footer, so the GitHub release goes to v1.4.0 (from the
featcommits) rather than v2.0.0.Testing
Tests run locally on net10.0 for every test project, and on net8.0 for DX.Utils.Tests and DX.Data.Xpo.Tests. Nothing is skipped and nothing fails.
🤖 Generated with Claude Code