https://github.com/godeltech/godeltech.database.entityframeworkcore
Library to work with database, apply migrations and data using Entity Framework Core
https://github.com/godeltech/godeltech.database.entityframeworkcore
Last synced: 24 days ago
JSON representation
Library to work with database, apply migrations and data using Entity Framework Core
- Host: GitHub
- URL: https://github.com/godeltech/godeltech.database.entityframeworkcore
- Owner: GodelTech
- License: mit
- Created: 2020-09-13T12:50:05.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-27T16:08:09.000Z (5 months ago)
- Last Synced: 2025-04-11T20:19:44.972Z (about 1 month ago)
- Language: C#
- Size: 131 KB
- Stars: 1
- Watchers: 10
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GodelTech.Database.EntityFrameworkCore
# Description
GodelTech.Database.EntityFrameworkCore is a .NET library designed to work with databases, apply migrations, and manage data using Entity Framework Core. It simplifies the process of creating console applications with database migrations and data operations.## Overview
Using this library you can create console app with database migrations and data.
`DatabaseService.cs`
```csharp
public class DatabaseService : DatabaseServiceBase
{
public DatabaseService(
BaseContext baseContext,
WeatherContext weatherContext,
IHostEnvironment hostEnvironment,
ILogger logger)
: base(logger, baseContext, weatherContext)
{
RegisterDataService(
new DataService(
new ConfigurationBuilder(),
hostEnvironment,
@"Data\Weather",
weatherContext,
false,
x => x.Id,
logger
)
);
}
}
````Worker.cs`
```csharp
public class Worker : BackgroundService
{
private readonly IServiceProvider _serviceProvider;
private readonly ILogger _logger;public Worker(IServiceProvider serviceProvider, ILogger logger)
{
_serviceProvider = serviceProvider;
_logger = logger;
}private static readonly Action LogExecuteAsyncApplyDatabaseMigrationsInformation =
LoggerMessage.Define(
LogLevel.Information,
new EventId(0, nameof(ExecuteAsync)),
"Apply database migrations"
);private static readonly Action LogExecuteAsyncApplyDatabaseDataInformation =
LoggerMessage.Define(
LogLevel.Information,
new EventId(0, nameof(ExecuteAsync)),
"Apply database data"
);protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
using var scope = _serviceProvider.CreateScope();
var databaseService = scope.ServiceProvider.GetRequiredService();LogExecuteAsyncApplyDatabaseMigrationsInformation(_logger, null);
await databaseService.ApplyMigrationsAsync();LogExecuteAsyncApplyDatabaseDataInformation(_logger, null);
await databaseService.ApplyDataAsync();
}
}
```# License
This project is licensed under the MIT License. See the LICENSE file for more details.