Make TypeMap injectable, with fluent TypeMap interface
See original GitHub issueIs there any way to add or override a specific TypeMap? I would like to make a one-off mapping to map a specific DbType to a specific Template without having to recreate the entire TypeMap class.
For example, SQLite does not support ‘DateTimeOffset’, but EFCore automatically serializes DateTimeOffset
to TEXT
within SQLite. When creating my Migrations, I know that I can use IfDatabase
to test for SQLite and another to test if not SQLite, creating the appropriate column type for each database engine, but this is a lot of repeated code for each of my DateTimeOffset columns.
Instead, it would be much easier to update the SQLiteTypeMap to somehow fire off SetTypeMap(DbType.DateTimeOffset, "TEXT");
. This would eliminate all of the IfDatabase
calls. However, with a lot of internal classes and instantiation within constructors, this seems difficult to do without duplicating most of FluentMigrator.Runner.SQLite
.
What am I missing? I can’t find any documentation for a one-off TypeMap override.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top GitHub Comments
I do think it would be worthwhile to be extensible. Even if EFCore didn’t automatically support serialization of
DateTimeOffset
, it would be helpful to say “Hey, I know that this database doesn’t natively support this data type, but I’ve created a custom mapping in my own codebase to handle it. So, whenever a migration is created for this data type, create the column using this other type, instead.”As you put it, the entire point of the Type Map system is abstracting away different data column type mappings. I don’t need everyone on the dev team knowing that SQLite doesn’t support DateTimeOffset and remembering to create their mappings using
IfDatabase
tests to store it as a string. Instead, our codebase can extend one new mapping condition to abstract that away and allAsDateTimeOffset
calls automatically handle the conversion.I will add a feature request.
@jayharris See also: https://github.com/fluentmigrator/fluentmigrator/issues/1032 - if you would like to help with this, that would be the first steps to considering making the meta model not just documented, but fungible by consumers.