Rewrite electricity server to .NET web api
This commit is contained in:
45
src/Electricity.Api/DatabaseContext.cs
Normal file
45
src/Electricity.Api/DatabaseContext.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Electricity.Api.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Electricity.Api
|
||||
{
|
||||
public partial class DatabaseContext : DbContext
|
||||
{
|
||||
public DatabaseContext()
|
||||
{
|
||||
}
|
||||
|
||||
public DatabaseContext(DbContextOptions<DatabaseContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<ElectricityLog> ElectricityLogs { get; set; } = null!;
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
optionsBuilder.UseSqlite("Data Source=test.db");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<ElectricityLog>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.ToTable("ElectricityLog");
|
||||
|
||||
entity.HasIndex(e => e.Date, "idx_Date");
|
||||
|
||||
entity.HasIndex(e => e.TimeUtc, "idx_TimeUtc");
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user