唐召明
authored
|
1
2
|
using FreeSql;
using HHECS.DAQHandle.Models;
|
唐召明
authored
|
3
|
using HHECS.EquipmentModel;
|
唐召明
authored
|
4
5
6
7
8
9
|
namespace HHECS.DAQHandle.DataAccess
{
/// <summary>
/// 数据库上下文
/// </summary>
|
唐召明
authored
|
10
11
12
13
|
/// <remarks>
/// <para>参考文档:<a href="https://freesql.net/guide/db-context.html">https://freesql.net/guide/db-context.html</a></para>
/// <para>注意:<see cref="DataContext"/> 对象多线程不安全</para>
/// </remarks>
|
唐召明
authored
|
14
15
|
public class DataContext : DbContext
{
|
唐召明
authored
|
16
|
public DbSet<Equipment> Equipment { get; set; } = null!;
|
唐召明
authored
|
17
|
|
唐召明
authored
|
18
|
public DbSet<EquipmentType> EquipmentType { get; set; } = null!;
|
唐召明
authored
|
19
|
|
唐召明
authored
|
20
|
public DbSet<EquipmentTypePropTemplate> EquipmentTypePropTemplate { get; set; } = null!;
|
唐召明
authored
|
21
|
|
唐召明
authored
|
22
|
public DbSet<EquipmentProp> EquipmentProp { get; set; } = null!;
|
唐召明
authored
|
23
24
25
26
27
|
public DbSet<EquipmentDataRecord> EquipmentDataRecord { get; set; } = null!;
public DbSet<EquipmentAlarmRecord> EquipmentAlarmRecords { get; set; } = null!;
|
李璐瑶
authored
|
28
|
public DbSet<EquipmentStatusRecordHistory> EquipmentStatusRecordHistorys { get; set; } = null!;
|
唐召明
authored
|
29
|
public DbSet<EquipmentStatusRecord> EquipmentStatusRecords { get; set; } = null!;
|
李璐瑶
authored
|
30
31
|
public DbSet<Project> Project { get; set; } = null!;
public DbSet<WareHouse> WareHouse { get; set; } = null!;
|
唐召明
authored
|
32
|
|
唐召明
authored
|
33
34
35
36
37
|
protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
builder.UseFreeSql(GlobalVar.FreeSql);
}
|
唐召明
authored
|
38
|
protected override void OnModelCreating(ICodeFirst codefirst)
|
唐召明
authored
|
39
|
{
|
唐召明
authored
|
40
41
42
|
codefirst.Entity<Equipment>(eb =>
{
eb.ToTable($"daq_equipment");
|
李璐瑶
authored
|
43
44
|
eb.HasIndex(x => x.Code).IsUnique();
|
唐召明
authored
|
45
46
47
48
|
});
codefirst.Entity<EquipmentType>(eb =>
{
|
李璐瑶
authored
|
49
|
eb.ToTable("daq_equipment_type");
|
唐召明
authored
|
50
51
52
53
|
});
codefirst.Entity<EquipmentProp>(eb =>
{
|
李璐瑶
authored
|
54
|
eb.ToTable("daq_equipment_prop");
|
唐召明
authored
|
55
56
57
|
});
codefirst.Entity<EquipmentTypePropTemplate>(eb =>
|
唐召明
authored
|
58
|
{
|
李璐瑶
authored
|
59
|
eb.ToTable("daq_equipment_type_prop_template");
|
唐召明
authored
|
60
61
62
63
|
eb.Property(p => p.PropType).HasColumnType("varchar(50)");
eb.Property(p => p.DataType).HasColumnType("varchar(50)");
});
|
李璐瑶
authored
|
64
65
66
67
68
69
70
71
|
codefirst.Entity<Project>(eb =>
{
eb.ToTable("daq_project");
});
codefirst.Entity<WareHouse>(eb =>
{
eb.ToTable("daq_warehouse");
});
|
李璐瑶
authored
|
72
73
74
75
|
codefirst.SyncStructure<Equipment>();
codefirst.SyncStructure<EquipmentType>();
codefirst.SyncStructure<EquipmentProp>();
codefirst.SyncStructure<EquipmentTypePropTemplate>();
|
唐召明
authored
|
76
77
78
|
}
}
}
|