update API for more simple approach.
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SoilMoistureAPI.Models;
|
||||
|
||||
namespace SoilMoistureAPI.Data
|
||||
{
|
||||
public class SoilMoistureContext : DbContext
|
||||
{
|
||||
public SoilMoistureContext(DbContextOptions<SoilMoistureContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<SoilMoisture> SoilMoistures { get; set; }
|
||||
public DbSet<Device> Devices { get; set; } // New DbSet for Devices
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
// Configure the primary key for Device
|
||||
modelBuilder.Entity<Device>()
|
||||
.HasKey(d => d.DeviceId);
|
||||
|
||||
// Configure one-to-many relationship
|
||||
modelBuilder.Entity<Device>()
|
||||
.HasMany(d => d.SoilMoistures)
|
||||
.WithOne(s => s.Device)
|
||||
.HasForeignKey(s => s.DeviceId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
SoilMoistureAPI/Data/SoilMoistureFlatContext.cs
Normal file
35
SoilMoistureAPI/Data/SoilMoistureFlatContext.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SoilMoistureAPI.Models;
|
||||
|
||||
namespace SoilMoistureAPI.Data
|
||||
{
|
||||
public class SoilMoistureFlatContext : DbContext
|
||||
{
|
||||
public DbSet<SoilMoistureFlat> SoilMoisturesFlat { get; set; }
|
||||
|
||||
public SoilMoistureFlatContext(DbContextOptions<SoilMoistureFlatContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
// Optionally configure the SoilMoistureFlat entity
|
||||
modelBuilder.Entity<SoilMoistureFlat>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.Property(e => e.DeviceId)
|
||||
.IsRequired();
|
||||
entity.Property(e => e.MoistureLevel)
|
||||
.IsRequired();
|
||||
entity.Property(e => e.Nickname)
|
||||
.IsRequired();
|
||||
|
||||
// Optionally, set default SQL for Timestamp if using SQL Server
|
||||
// entity.Property(e => e.Timestamp).HasDefaultValueSql("GETUTCDATE()");
|
||||
});
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user