I am using DbProviderFactories in my data layer (based on Entity Framework) and am using SQLite for my database, but I don\'t have to have a App.Config to have the following
LATE ANSWER:
You can always directly get a factory like this:
DbProviderFactory factory = System.Data.SQLite.SQLiteFactory.Instance;
// (note that the rest of the code is still provider-agnostic.)
Or use your IoC container to resolve the DbProviderFactory
, e.g.:
container.RegisterInstance<DbProviderFactory>(SQLiteFactory.Instance);
I prefer not to use the DbProviderFactories.GetFactory
because of its limitation of requiring a configuration file (or a hack like in @JoshRiver's answer).
All DbProviderFactories.GetFactory
does is, it looks up the registered assembly-qualified name of the factory type using the provider name, and then it gets the value of the static Instance
property using reflection.
If you don't want to use the configuration, one of the methods above might be more convenient depending on your use case.
see the following snippet
public DataProviderManager(string ProviderName)
{
var _Provider = DbProviderFactories.GetFactory(ProviderName);
}
you need to pass the ProviderName that in your case is "System.Data.SQLite".
you don't need to create the app config section. That section is created by SQLite in the machine.config after the SQLite.net provider is installed.
the whole purpose of the appconfig section is to help you get the list of configured .net providers when you call the following command:
public GetProvidersList() { DataTable table= DbProviderFactories.GetFactoryClasses(); }