/// <summary> /// Returns LINQ To DB provider, based on provider data from EF.Core. /// Could be overriden if you have issues with default detection mechanisms. /// </summary> /// <param name="providerInfo">Provider information, extracted from EF.Core.</param> /// <param name="connectionInfo"></param> /// <returns>LINQ TO DB provider instance.</returns> public virtual IDataProvider GetDataProvider(EFProviderInfo providerInfo, EFConnectionInfo connectionInfo) { var info = GetLinqToDbProviderInfo(providerInfo); return(_knownProviders.GetOrAdd(new ProviderKey(info.ProviderName, connectionInfo.ConnectionString), k => { return CreateLinqToDbDataProvider(providerInfo, info, connectionInfo); })); }
protected virtual IDataProvider CreateLinqToDbDataProvider(EFProviderInfo providerInfo, LinqToDBProviderInfo provInfo, EFConnectionInfo connectionInfo) { if (provInfo.ProviderName == null) { throw new LinqToDBForEFToolsException("Can not detect data provider."); } switch (provInfo.ProviderName) { case ProviderName.SqlServer: return(CreateSqlServerProvider(SqlServerDefaultVersion, connectionInfo.ConnectionString)); case ProviderName.MySql: return(new MySqlDataProvider()); case ProviderName.PostgreSQL: return(CreatePotgreSqlProvider(PotgreSqlDefaultVersion, connectionInfo.ConnectionString)); case ProviderName.SQLite: return(new SQLiteDataProvider()); case ProviderName.Firebird: return(new FirebirdDataProvider()); case ProviderName.DB2: return(new DB2DataProvider(ProviderName.DB2, DB2Version.LUW)); case ProviderName.DB2LUW: return(new DB2DataProvider(ProviderName.DB2, DB2Version.LUW)); case ProviderName.DB2zOS: return(new DB2DataProvider(ProviderName.DB2, DB2Version.zOS)); case ProviderName.Oracle: return(new OracleDataProvider()); case ProviderName.SqlCe: return(new SqlCeDataProvider()); //case ProviderName.Access: // return new AccessDataProvider(); default: throw new LinqToDBForEFToolsException($"Can not instantiate data provider '{provInfo.ProviderName}'."); } }
protected virtual LinqToDBProviderInfo GetLinqToDbProviderInfo(EFProviderInfo providerInfo) { var provInfo = new LinqToDBProviderInfo(); var relational = providerInfo.Options?.Extensions.OfType <RelationalOptionsExtension>().FirstOrDefault(); if (relational != null) { provInfo.Merge(GetLinqToDbProviderInfo(relational)); } if (providerInfo.Connection != null) { provInfo.Merge(GetLinqToDbProviderInfo(providerInfo.Connection)); } if (providerInfo.Context != null) { provInfo.Merge(GetLinqToDbProviderInfo(providerInfo.Context.Database)); } return(provInfo); }