Skip to content

Do not force json to use JSON functions#2009

Open
Tobbeman wants to merge 1 commit intoPomeloFoundation:mainfrom
Tobbeman:feature/do-not-force-json
Open

Do not force json to use JSON functions#2009
Tobbeman wants to merge 1 commit intoPomeloFoundation:mainfrom
Tobbeman:feature/do-not-force-json

Conversation

@Tobbeman
Copy link
Copy Markdown

We are using scaffolding to create our database classes. Sadly, the scaffold does not support json on the json field, instead opting for string.

This change will let the user use JSON functions more freely

We are using scaffolding to create our database classes.
Sadly, the scaffold does not support json on the json field, instead opting for string.

This change will let the user use JSON functions more freely
@lara-ec
Copy link
Copy Markdown

lara-ec commented Feb 4, 2026

In case this is helpful for anyone: our solution for this was editing the EntityType.t4 template to not annotate the string columns as json:

before:

            foreach (var dataAnnotation in dataAnnotations)
            {
#>
    <#= code.Fragment(dataAnnotation) #>
<#
            }

after:

            foreach (var dataAnnotation in dataAnnotations)
            {
                var annotation = dataAnnotation;
                if (
                    dataAnnotation.Type == typeof(System.ComponentModel.DataAnnotations.Schema.ColumnAttribute)
                    && dataAnnotation.NamedArguments.TryGetValue("TypeName", out var typeName)
                    && typeName is "json"
                )
                {
                    annotation = new AttributeCodeFragment(
                        annotation.Type,
                        annotation.Arguments,
                        annotation.NamedArguments.Where(n => n.Key != "TypeName").ToDictionary()
                    );

#>
    // this is a json column
<#
                }
#>
    <#= code.Fragment(annotation) #>
<#
            }

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.

3 participants