question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make TypeMap injectable, with fluent TypeMap interface

See original GitHub issue

Is 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:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
jayharriscommented, Sep 24, 2019

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 all AsDateTimeOffset calls automatically handle the conversion.

I will add a feature request.

1reaction
jzabroskicommented, Sep 24, 2019

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typemaps
As the name implies, the purpose of a typemap is to "map" C datatypes to types in the target language. Once a typemap...
Read more >
Programming to interfaces while mapping with Fluent ...
Essentially, you create a mapping definition for the base class (in this case your interface) and specify how to NHibernate should deal with ......
Read more >
Effective Dart: Design
Here are some guidelines for writing consistent, usable APIs for libraries. Names. Naming is an important part of writing readable, maintainable code.
Read more >
AutoMapper — AutoMapper documentation
AutoMapper uses a fluent configuration API to define an object-object mapping strategy. AutoMapper uses a convention-based matching algorithm to match up ...
Read more >
Jdbi 3 Developer Guide
The Core API provides a fluent, imperative interface. Use Builder style objects to wire up your SQL to rich Java data types.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found