Я сделал это, используя обходной путь.Ниже приведен код.
public abstract class BaseDataService
{
private Database database = null;
public BaseDataService()
{
DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(new SystemConfigurationSource(false).GetSection), false);
this.database = DatabaseFactory.CreateDatabase("_connection");
}
public Database SqlDatabase
{
get
{
return this.database;
}
set
{
this.database = value;
}
}
}
Файл App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="system.data" type="System.Data.Common.DbProviderFactoriesConfigurationHandler, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</configSections>
<connectionStrings>
<add name="_connection" connectionString="Server=localhost;Database=DBNAME;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Использование
public class MyDataService : BaseDataService
{
public IList<Test> ReadTest()
{
IList<Test> testList = new List<Test>();
DbCommand selectCommand = null;
selectCommand = SqlDatabase.GetStoredProcCommand("[dbo].[CSP_Test_SelectAll]");
using (DataSet result = SqlDatabase.ExecuteDataSet(selectCommand))
{
if (result.Tables[0].Rows.Count > 0)
{
DataTable dataTable = result.Tables[0];
feesList = dataTable.ConvertTo<Test>();
}
}
return testList;
}
}
Необходимые пакеты
<PackageReference Include="EnterpriseLibrary.Data.NetCore" Version="6.0.1313" />
Редактировать:
Я просмотрел ваш код, и проблема в получении значений конфигурации
public DatabaseConnection(IConfiguration configuration)
{
string connectionString = configuration.GetConnectionString("DefaultConnection");
sqlAdapter = new SqlDataAdapter();
sqlConnection = new SqlConnection(connectionString);
}