Add SQL Server 2025 JSON data type support#1
Draft
bold-hen wants to merge 5 commits into
Draft
Conversation
Introduce comprehensive JSON type support for the ORM, enabling fields derived from the new JsonType base class to be stored as JSON columns with LINQ translation for property access via JSON_VALUE/JSON_QUERY. Core type system: - JsonType abstract base class as marker for JSON-storable types - SqlType.Json for the native SQL Server 2025 json data type - FieldAttributes.Json flag and FieldInfo.IsJson property - JsonFieldAccessor for System.Text.Json serialization/deserialization - FieldDef/TypeBuilder support for single-column JSON field mapping SQL DOM layer: - SqlFunctionType entries for JSON_VALUE, JSON_QUERY, JSON_MODIFY, ISJSON, and JSON_PATH_EXISTS - SqlDml factory methods for all JSON functions - SqlTranslator mappings to SQL function names - DataTypeCollection.Json property for type registration SQL Server v17 driver: - New v17 driver inheriting from v13 for SQL Server 2025+ - ServerInfoProvider registers native json data type - Compiler, Translator, Extractor, TypeMapper implementations - DriverFactory routes version >= 17 to v17 driver - Fallback to nvarchar(max) on older SQL Server versions LINQ translation: - JsonFieldExpression with JSON path tracking for property access - ExtendedExpressionType.JsonField and visitor infrastructure - Translator.GetMember handles JSON member access via CreatePropertyAccess - ExpressionMaterializer generates JsonExpressionHelper.JsonValue calls - JsonCompilers translate to SqlDml.JsonValue/JsonQuery for SQL generation - ColumnGatherer support for JSON field column tracking - Type conversion via Expression.Convert with Parse methods for non-string properties (generates CAST in SQL) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix JsonCompilers: add TargetKind.Static flag for static method compilers - Fix Validator: recognize JsonType subclasses as valid field types - Fix ModelInspector: add early return for JSON fields to prevent erroneous model type lookup - Add TestJsonInOrm integration test project Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ve tests - Add JsonTypeArray<T> generic collection type for JSON arrays with change tracking - Add JsonArrayFieldAccessor and JsonTrackedCollection for proper persistence - Add OpenJsonProvider (OPENJSON) support for SelectMany over JSON arrays - Add numeric Parse method compilers so JSON property access works in joins/expressions - Add JsonTypeArray<T> element type validation (must inherit from JsonType) - Add comprehensive NUnit tests covering SQL column types, change tracking, server-side Select, Join operations, and SelectMany projections - Update SQL Server v17 driver to handle native JSON type compilation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add snapshot-based dirty checking for scalar JsonType fields via JsonFieldValueAdapter<T> — inner property mutations (e.g., owner.JsonField.StringField = "x") are now automatically detected and persisted without requiring whole-object reassignment - Convert JsonFieldAccessor to CachingFieldAccessor pattern so repeated access returns the same cached instance - Add IJsonFieldValueAdapter interface with FlushIfDirty() for pre-persist snapshot comparison - Extend JsonTypeArray with snapshot comparison to detect inner item property mutations (e.g., array[0].Name = "x") - Add session-level JsonFieldAdapters registry and FlushDirtyJsonFields() hook in Session.Persist before EntityChangeRegistry check - Restructure tests: move LINQ tests to Linq/JsonLinqTest.cs, keep storage/change-tracking tests in Storage/JsonTypeTest.cs - Remove TestJsonInOrm scratch project from solution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…pertyChanged
Replace snapshot-based dirty checking with proper INPC pattern:
- JsonType now implements INotifyPropertyChanged with OnPropertyChanged()
- ORM Weaver detects JsonType subclasses (new PersistentTypeKind.JsonType)
and injects OnPropertyChanged("PropName") calls into property setters
via ImplementJsonPropertyNotificationTask
- JsonFieldAccessor subscribes to PropertyChanged on cached instances and
immediately writes changes to the entity tuple (no flush-time re-serialization)
- JsonTypeArray subscribes to each item's PropertyChanged for inner mutations
- Remove snapshot infrastructure: delete JsonFieldValueAdapter, remove
IJsonFieldValueAdapter, FlushDirtyJsonFields, and Session-level registry
Co-Authored-By: Claude Opus 4.6 <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
jsondata type support for SQL Server 2025 (v17+), withnvarchar(max)fallback on older versionsJsonTypebase class for POCO types stored as single JSON columns, andJsonTypeArray<T>for JSON array collections with generic type validationJSON_VALUE, array expansion viaCROSS APPLY OPENJSON, joins and aggregation on JSON fieldsINotifyPropertyChanged— the ORM Weaver detectsJsonTypesubclasses and injectsOnPropertyChangedcalls into property setters, so changes likeowner.JsonField.Name = "x"are tracked without whole-object reassignmentParsemethod compilers (int.Parse,decimal.Parse, etc.) so JSON property access works in join keys and server-side expressionsCompiler,Translator,TypeMapper,ServerInfoProvider, andExtractorKey design decisions
JsonTypeis a lightweight base class implementingINotifyPropertyChanged— properties are plain C# auto-properties serialized viaSystem.Text.JsonImplementJsonPropertyNotificationTaskappendsOnPropertyChanged("PropName")IL to each auto-property setter;JsonFieldAccessorsubscribes toPropertyChangedand immediately writes changes to the entity tupleJsonTypeArray<T>subscribes to each item'sPropertyChangedfor inner mutations, and persists eagerly on collection mutations (Add/Remove/Clear)JsonTypeArray<T>element type validated at domain build time (must inherit fromJsonType)Test plan
jsoncolumn type on SQL Server 2025,nvarchar(max)on older versionsJsonTypeArraytracking: Add, Remove, Clear, indexer set, inner item mutation