Closed PhilPJL closed 2 years ago
Good idea. I'll add that.
In the meantime, you can use this code.
Thanks. Works fine. Shame it doesn't work for .NET 4.8 as well.
My final(-ish) code is
public static void Main(string[] args)
{
...
#if !NETFRAMEWORK
DbProviderFactories.RegisterFactory(FbProviderServices.ProviderInvariantName, FirebirdClientFactory.Instance);
#else
var dataSet = ConfigurationManager.GetSection("system.data") as System.Data.DataSet;
dataSet.Tables[0].Rows.Add("FirebirdClient"
, "FirebirdClient"
, "FirebirdSql.Data.FirebirdClient"
, "FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient");
#endif
DbConfiguration.SetConfiguration(new FirebirdConfiguration() { });
...
}
private sealed class FirebirdConfiguration : DbConfiguration
{
public FirebirdConfiguration()
{
SetProviderServices(FbProviderServices.ProviderInvariantName, FbProviderServices.Instance);
}
}
So no need for app.config at all.
Had the same requirement some time ago, did the following
internal class Foo : IFoo
{
internal class DpResolver : IDbDependencyResolver
{
public object GetService(Type type, object key)
{
if (type == typeof(DbProviderFactory))
return FirebirdClientFactory.Instance;
if (type == typeof(IProviderInvariantName))
return new DpInvariantName();
return null;
}
public IEnumerable<object> GetServices(Type type, object key)
{
return new[] { GetService(type, key) }.ToList().Where(o => o != null);
}
class DpInvariantName : IProviderInvariantName
{
public string Name { get; } = EntityFramework.Firebird.FbProviderServices.ProviderInvariantName;
}
}
static Foo()
{
#if NET47
System.Data.Entity.DbConfiguration.Loaded += (_, args) =>
{
args.AddDependencyResolver(new DpResolver(), true);
};
#else
DbProviderFactories.RegisterFactory(EntityFramework.Firebird.FbProviderServices.ProviderInvariantName, FirebirdClientFactory.Instance);
#endif
}
}
Code is ~2years old, don't really remember why I did it this way.
Done via 89e3ddb34284bdf6078fbc0d6acd0622f1f0de9a.
I'm currently migrating an app from .NET Framework to .NET 6 and for now making the app multi-target. Using EntityFramework.Firebird 9.01 on .NET 4.8 and .NET 6. Problem is that this works fine for .NET 4.8 in app.config, but not supported in .NET 6
I'll (try to) track down how to do it in code, but would be great if was added to your documentation.