DataContext.cs
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using DataAcquisition.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ValueGeneration;
namespace DataAcquisition.DataAccess
{
public sealed class DataContext(DbContextOptions options) : DbContext(options)
{
public DbSet<WorkpieceModel> WorkpieceModels => Set<WorkpieceModel>();
public DbSet<Equipment> Equipments => Set<Equipment>();
public DbSet<EquipmentProperty> EquipmentProperties => Set<EquipmentProperty>();
public DbSet<CommunicationConfig> CommunicationConfigs => Set<CommunicationConfig>();
public DbSet<EquipmentPropertyRecord> EquipmentPropertyRecords => Set<EquipmentPropertyRecord>();
public DbSet<WorkpieceProduction> WorkpieceProductions => Set<WorkpieceProduction>();
public DbSet<EquipmentDataQueue> EquipmentDataQueues => Set<EquipmentDataQueue>();
public DbSet<WeldProcessRecord> WeldProcessRecords => Set<WeldProcessRecord>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<EquipmentPropertyRecord>(entity => entity.Property(e => e.Id).HasValueGenerator<SequentialGuidValueGenerator>());
modelBuilder.Entity<WorkpieceProduction>(entity => entity.Property(e => e.Id).HasValueGenerator<SequentialGuidValueGenerator>());
modelBuilder.Entity<EquipmentDataQueue>(entity => entity.Property(e => e.Id).HasValueGenerator<SequentialGuidValueGenerator>());
modelBuilder.Entity<WeldProcessRecord>(entity => entity.Property(e => e.Id).HasValueGenerator<SequentialGuidValueGenerator>());
modelBuilder.Entity<CommunicationConfig>().Property(x => x.CommunicationType).HasConversion<string>();
modelBuilder.Entity<Equipment>().Property(x => x.EquipmentType).HasConversion<string>();
modelBuilder.Entity<EquipmentProperty>().Property(x => x.DataType).HasConversion<string>();
modelBuilder.Entity<CommunicationConfig>().HasData(DataSeeding.GetCommunicationConfigs());
modelBuilder.Entity<Equipment>().HasData(DataSeeding.GetEquipments());
modelBuilder.Entity<EquipmentProperty>().HasData(DataSeeding.GetEquipmentProperties());
base.OnModelCreating(modelBuilder);
}
}
}