Add JobRunnerDbContext with multi-framework support
Introduce `JobRunnerDbContext` to support both EF6 (.NET 4.8) and EF Core (.NET 8) using conditional compilation. Add `DbSet` properties for `CfgProfiles`, `ProfileSqlJobs`, and `ProfileHistories`. Provide constructors for both frameworks to handle connection strings or options. Ensure compatibility with multiple runtime environments.
This commit is contained in:
53
ECMJobRunner.Infrastructure/Data/JobRunnerDbContext.cs
Normal file
53
ECMJobRunner.Infrastructure/Data/JobRunnerDbContext.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
#if NET48
|
||||
using System.Data.Entity;
|
||||
#else
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
#endif
|
||||
using ECMJobRunner.Domain.Entities;
|
||||
|
||||
namespace ECMJobRunner.Infrastructure.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Entity Framework DbContext for ECM Job Runner
|
||||
/// </summary>
|
||||
public class JobRunnerDbContext : DbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Profile entities
|
||||
/// </summary>
|
||||
public DbSet<CfgProfile> CfgProfiles { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// ProfileSqlJob entities
|
||||
/// </summary>
|
||||
public DbSet<ProfileSqlJob> ProfileSqlJobs { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// ProfileHistory entities
|
||||
/// </summary>
|
||||
public DbSet<ProfileHistory> ProfileHistories { get; set; } = null!;
|
||||
|
||||
#if NET48
|
||||
/// <summary>
|
||||
/// Default constructor for Entity Framework 6 (.NET Framework 4.8)
|
||||
/// </summary>
|
||||
public JobRunnerDbContext() : base("name=JobRunnerConnection")
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with connection string for Entity Framework 6
|
||||
/// </summary>
|
||||
public JobRunnerDbContext(string connectionString) : base(connectionString)
|
||||
{
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Constructor for Entity Framework Core (.NET 8)
|
||||
/// </summary>
|
||||
public JobRunnerDbContext(DbContextOptions<JobRunnerDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user