EntityFrameworkCoreHelpers 1.0.0
See the version list below for details.
dotnet add package EntityFrameworkCoreHelpers --version 1.0.0
NuGet\Install-Package EntityFrameworkCoreHelpers -Version 1.0.0
<PackageReference Include="EntityFrameworkCoreHelpers" Version="1.0.0" />
paket add EntityFrameworkCoreHelpers --version 1.0.0
#r "nuget: EntityFrameworkCoreHelpers, 1.0.0"
// Install EntityFrameworkCoreHelpers as a Cake Addin #addin nuget:?package=EntityFrameworkCoreHelpers&version=1.0.0 // Install EntityFrameworkCoreHelpers as a Cake Tool #tool nuget:?package=EntityFrameworkCoreHelpers&version=1.0.0
About
Provides the following methods for connecting to a SQL-Server database.
Note
Current uses Microsoft.EntityFrameworkCore.SqlServer
version 5.0.9, next release will accept higher releases of this package.
Place the following appsettings.json file into a project, set to copy if newer
- Populate each environment with appropriate connection strings.
- Set
ActiveEnvironment
to the desired environment. - Use one of the connection methods below in your DbContext class.
{
"ConnectionsConfiguration": {
"ActiveEnvironment": "Production",
"Development": "Dev connection string goes here",
"Stage": "Stage connection string goes here",
"Production": "Prod connection string goes here"
}
}
Connect without logging
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
DbContextConnections.NoLogging(optionsBuilder);
}
}
Connect with logging via Debug.WriteLine
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
DbContextConnections.StandardLogging(optionsBuilder);
}
}
Connect with logging to a folder named Logs under the current application folder.
Note the folder Logs must exist while the log file does not need to exists. To ensure the folder exist consider a msbuild task (see below)
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
DbContextConnections.CustomLogging(optionsBuilder);
}
}
public class DbContextConnections
{
/// <summary>
/// Simple configuration for setting the connection string
/// </summary>
public static void NoLogging(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(ConfigurationHelper.ConnectionString());
}
/// <summary>
/// Default logging to output window
/// </summary>
public static void StandardLogging(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(ConfigurationHelper.ConnectionString())
.EnableSensitiveDataLogging()
.LogTo(message => Debug.WriteLine(message));
}
/// <summary>
/// Writes/appends to a file
/// Make sure that the folder exists, as coded folder name is Logs under the app folder.
/// One way to ensure the folder exists is to use MsBuild task MakeDir as in
/// the test project ShadowPropertiesUnitTestProject.
/// </summary>
public static void CustomLogging(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(ConfigurationHelper.ConnectionString())
.EnableSensitiveDataLogging()
.LogTo(new DbContextLogger().Log)
.EnableSensitiveDataLogging()
.EnableDetailedErrors();
}
}
msbuild MakeDir
<Target Name="MakeLogFolder" AfterTargets="Build">
<MakeDir Directories="$(OutDir)Logs" />
</Target>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net5.0
- ConfigurationLibrary (>= 1.0.1)
- Microsoft.EntityFrameworkCore.SqlServer (>= 5.0.9)
- Microsoft.Extensions.Configuration (>= 5.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 5.0.0)
- Microsoft.Extensions.Configuration.FileExtensions (>= 5.0.0)
- Microsoft.Extensions.Configuration.Json (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
All code works. Current constrained to 5.0.9 for Microsoft.EntityFrameworkCore.SqlServer package. Next release will resolve this constraint.