Files
FA_WEB/AzureDataModel/AzureDbContext.cs
Piotr Kus e7342abadd * Created AzureDataModel
* Created Hangfire API
2025-02-12 20:29:10 +01:00

40 lines
1.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using TaskScheduler = AzureDataModel.Entities.TaskScheduler;
namespace AzureDataModel;
public class AzureDbContext : DbContext
{
public AzureDbContext(DbContextOptions<AzureDbContext> options)
: base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var connectionString = configuration.GetConnectionString("AzureConnection");
optionsBuilder.UseAzureSql(connectionString, options => options.CommandTimeout(300));
}
public DbSet<TaskScheduler> TaskSchedulers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TaskScheduler>()
.HasKey(e => e.Id);
modelBuilder.Entity<TaskScheduler>()
.Property(e => e.RowPointer)
.HasDefaultValueSql("newid()");
modelBuilder.Entity<TaskScheduler>()
.Property(e => e.CreateDate)
.HasDefaultValueSql("getdate()");
}
}