DataContext.cs
1.88 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
43
44
45
46
47
48
49
50
51
using FreeSql;
using HHECS.DAQClient.Model;
using HHECS.EquipmentModel;
namespace HHECS.DAQClient.DataAccess
{
/// <summary>
/// 数据库上下文
/// </summary>
/// <remarks>参考文档:<a href="https://freesql.net/guide/db-context.html">https://freesql.net/guide/db-context.html</a></remarks>
public sealed class DataContext : DbContext
{
public DbSet<CommunicationConfig> CommunicationConfigs { get; set; } = null!;
public DbSet<Equipment> Equipment { get; set; } = null!;
public DbSet<EquipmentProp> EquipmentProp { get; set; } = null!;
public DbSet<EquipmentType> EquipmentType { get; set; } = null!;
public DbSet<EquipmentTypePropTemplate> EquipmentTypePropTemplate { get; set; } = null!;
public DbSet<EquipmentDataQueue> EquipmentDataQueue { get; set; } = null!;
protected override void OnModelCreating(ICodeFirst codefirst)
{
codefirst.Entity<CommunicationConfig>(eb =>
{
eb.Property(p => p.CommunicationType).HasColumnType("varchar(50)").Help().MapType(typeof(string));
eb.HasData(DataSeeding.GetCommunicationConfigs());
});
codefirst.Entity<EquipmentType>(eb =>
{
eb.HasData(DataSeeding.GetEquipmentTypes());
});
codefirst.Entity<EquipmentTypePropTemplate>(eb =>
{
eb.Property(p => p.PropType).HasColumnType("varchar(50)").Help().MapType(typeof(string));
eb.Property(p => p.DataType).HasColumnType("varchar(50)").Help().MapType(typeof(string));
eb.HasData(DataSeeding.GetEquipmentTypePropTemplates());
});
codefirst.SyncStructure<CommunicationConfig>();
codefirst.SyncStructure<EquipmentType>();
codefirst.SyncStructure<EquipmentTypePropTemplate>();
}
}
}