Files
Modbus.Net/Samples/MachineJob/DatabaseWrite.cs
luosheng 25555cad18 Fix
2023-06-28 16:38:00 +08:00

44 lines
1.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace MachineJob
{
public class DatabaseWriteContext : DbContext
{
private static readonly IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.default.json", optional: false, reloadOnChange: true)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true, reloadOnChange: true)
.Build();
private static readonly string connectionString = configuration.GetConnectionString("DatabaseWriteConnectionString")!;
public DbSet<DatabaseWriteEntity> DatabaseWrites { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
}
}
[Table(name: "databasewrites")]
public class DatabaseWriteEntity
{
[Key]
public int Id { get; set; }
public double? Value1 { get; set; }
public double? Value2 { get; set; }
public double? Value3 { get; set; }
public double? Value4 { get; set; }
public double? Value5 { get; set; }
public double? Value6 { get; set; }
public double? Value7 { get; set; }
public double? Value8 { get; set; }
public double? Value9 { get; set; }
public double? Value10 { get; set; }
public DateTime UpdateTime { get; set; }
}
}