Provides a generic Mendz.Data-aware context for ADO.Net-compatible access to SQL Server databases. Wiki
Mendz.Data.SqlServer
Name | Description |
---|---|
SqlServerDbDataContext | Provides the database context for an SQL Server database. |
SqlServerDataSettingOption | Provides the data setting options for SQL Server access. |
Mendz.Data.Common defines an IDbDataContext interface, which is implemented as GenericDbDataContextBase, which is derived by DbDataContextBase. SqlServerDbDataContext derives from DbDataContextBase, which requires the abstract BuildContext() method to be implemented. The internal implementation uses Mendz.Data.DataSettingOptions to build the data context. SqlServerDbDataContext.BuildContext() will first look for SqlServerDataSettingOption.Name. If it's not available, it will look for SqlServerDataSettingOption.AlternativeName.
SqlServerDbDataContext assumes that appsettings.json contains an entry/section for DataSettings.
{
"DataSettings": {
"ConnectionStrings": {
"SqlServerConnectionString" : "connection string to Sql Server",
"SqlServerExpressConnectionString" : "connection string to Sql Server express (LocalDB)"
}
}
}
In the application startup or initialization routine, the DataSettings should be loaded into DataSettingOptions as follows:
public Startup(IConfiguration configuration)
{
Configuration = configuration;
DataSettingOptions.Initialize(Configuration.GetSection("DataSettings").Get<DataSettings>());
}
Mendz.Data-aware repositories implement DbRepositoryBase, which expects a Mendz.Data-aware data context. Using SqlServerDbDataContext, a repository skeleton can look like the following:
public class TestRepository : DbRepositoryBase<SqlServerDbDataContext>
{
...
}
Using Mendz.Data can shield the application from "knowing" about the data context. The application does not need to reference Mendz.Data.SqlServer. The application can reference only Mendz.Data, and the models and repositories libraries.