Skip to content

Generating arbitrary-type C# literals for seed data in migrations #12979

Closed as duplicate

Description

@roji

In npgsql/efcore.pg#575, an Npgsql user complained about not being able to create migrations which seed NodaTime data. The issue is that the migration scaffolding process currently uses a built-in, hardcoded CSharpHelper which knows how to generate C# literals for a closed set of types. For example, it knows to generate DateTime literals, but not NodaTime Instant.

I could extend CSharpHelper and register my own service, which adds support for NodaTime and other types - but if we want to go down that route it would be better for CSharpHelper to not be internal.

Another more radical idea would be to transfer responsibility for C# literal generation to the type mappings, which are already responsible for generating SQL literals. The CSharpHelper would then simply look up the proper mapping on the TypeMappingSource based on the given ClrType, and call a method on that. It could be argued that this isn't the concern of type mappings, since it's a purely .NET-side thing (nothing to do with the database). In addition, care must be taken if we want to add support for scaffolding migrations for non-C# languages (F#, VB.NET) - it would probably mean that providers are responsible for generating literals for their provider-specific types, in all languages.

/cc @bricelam

Activity

  1. ajcvickers commented on Aug 13, 2018

    @ajcvickers
    Contributor

    @roji We have discussed doing this in the past and @bricelam filed #8741 for it. I'll reference this issue from there and close this as a dupe. For now, I expect the best that can be done is the override the internal service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions