EntityFrameworkCore.Jet
EntityFrameworkCore.Jet copied to clipboard
[ .net 5 ] : EnsureCreated always use ODBC
When executing ~~Migrate
or MigrateAsync
~~ EnsureCreated
and EnsureCreatedAsync
, it doesn't matter which connection string we use, the provider will always use ODBC.
In my case, I'm working with OLEDB and I want EnsureCreated
to use OLEDB too, the reason is that I'm using some datatypes that doesn't works well with ODBC but everything works perfectly with OLEDB.
Not 100% sure, but looks like the JetDatabaseCreator
invoke the CreateEmptyConnection
method which for some reason retrieves ODBC by default.
As extra information, if you use Migrate
and MigrateAsync
, it uses OLEDB and migration just creates the database correctly.
For more information, I'm using this workaround to create the database when using JET provider:
var databaseCreator = JetDatabaseCreator.CreateInstance(SchemaProviderType.Adox);
databaseCreator.CreateDatabase(theConnectionString);
This one works and creates the empty database, so later I can apply the Migration with Context.Database.Migrate() without any problem.
@nicovil Sorry can you clarify a bit, since the following two statements seem contradict each other:
When executing Migrate or MigrateAsync, it doesn't matter which connection string we use, the provider will always use ODBC. [...] As extra information, if you use Migrate and MigrateAsync, it uses OLEDB and migration just creates the database correctly.
Thanks!
Hi @lauxjpn.
Sorry for the confusion, what's wrong is the first sentence.
Where it says: When executing Migrate or MigrateAsync, it doesn't matter which connection string we use, the provider will always use ODBC.
It should say: When executing EnsureCreated and EnsureCreatedAsync, it doesn't matter which connection string we use, the provider will always use ODBC.
As I mention in a latter comment, by debugging Jet provider code I found a workaround to create the empty database by using:
var databaseCreator = JetDatabaseCreator.CreateInstance(SchemaProviderType.Adox);
databaseCreator.CreateDatabase(theConnectionString);
Sorry for my error.
@nicovil Thanks, got it now! I'll take a look at this.
Fixed as part of #135