DataContext.cs
1.07 KB
using HHECS.RobotTool.Model;
using Microsoft.EntityFrameworkCore;
namespace HHECS.RobotTool.DataAccess
{
public sealed class DataContext(DbContextOptions options) : DbContext(options)
{
public DbSet<CommunicationConfig> CommunicationConfigs => Set<CommunicationConfig>();
public DbSet<Equipment> Equipment => Set<Equipment>();
public DbSet<EquipmentProperty> EquipmentProps => Set<EquipmentProperty>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CommunicationConfig>().Property(x => x.CommunicationType).HasConversion<string>();
modelBuilder.Entity<EquipmentProperty>().Property(x => x.DataType).HasConversion<string>();
modelBuilder.Entity<CommunicationConfig>().HasData(DataSeeding.GetCommunicationConfigs());
modelBuilder.Entity<Equipment>().HasData(DataSeeding.GetEquipment());
modelBuilder.Entity<EquipmentProperty>().HasData(DataSeeding.GetEquipmentProps());
base.OnModelCreating(modelBuilder);
}
}
}