You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generating arbitrary-type C# literals for seed data in migrations #12979
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.
@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.
Activity
ajcvickers commentedon Aug 13, 2018
@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.