ActionConfigurationConfiguration.cs
3.18 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Rcs.Domain.Entities;
namespace Rcs.Infrastructure.DB.Configuration.Domain
{
/// <summary>
/// ActionConfiguration实体的EF Core配置
/// </summary>
public class ActionConfigurationConfiguration : IEntityTypeConfiguration<ActionConfiguration>
{
public void Configure(EntityTypeBuilder<ActionConfiguration> builder)
{
// 配置表名(已在实体上通过Table特性配置)
builder.ToTable("action_configurations");
// 配置主键
builder.HasKey(e => e.ActionConfigId);
// 配置属性
builder.Property(e => e.ActionConfigId)
.HasColumnName("action_config_id")
.ValueGeneratedNever();
builder.Property(e => e.ActionCategory)
.HasColumnName("action_category")
.IsRequired();
builder.Property(e => e.ActionCategoryName)
.HasColumnName("action_category_name")
.HasMaxLength(100);
builder.Property(e => e.Manufacturer)
.HasColumnName("manufacturer")
.HasMaxLength(100)
.IsRequired();
builder.Property(e => e.RobotType)
.HasColumnName("robot_type")
.IsRequired();
builder.Property(e => e.ActionName)
.HasColumnName("action_name")
.HasMaxLength(100)
.IsRequired();
builder.Property(e => e.ActionDescription)
.HasColumnName("action_description")
.HasMaxLength(500);
builder.Property(e => e.ExecutionScope)
.HasColumnName("execution_scope")
.HasColumnType("text");
builder.Property(e => e.BlockingType)
.HasColumnName("blocking_type")
.IsRequired();
builder.Property(e => e.IsEnabled)
.HasColumnName("is_enabled")
.HasDefaultValue(true);
builder.Property(e => e.SortOrder)
.HasColumnName("sort_order")
.HasDefaultValue(0);
builder.Property(e => e.Remarks)
.HasColumnName("remarks")
.HasMaxLength(1000);
builder.Property(e => e.CreatedAt)
.HasColumnName("created_at")
.HasColumnType("timestamp without time zone");
builder.Property(e => e.UpdatedAt)
.HasColumnName("updated_at")
.HasColumnType("timestamp without time zone");
// 配置索引
builder.HasIndex(e => new { e.Manufacturer, RobotType = e.RobotType, e.ActionCategory })
.HasDatabaseName("idx_action_config_lookup");
builder.HasIndex(e => e.ActionName)
.HasDatabaseName("idx_action_config_name");
// 配置导航属性 - 一对多关系
builder.HasMany(e => e.Parameters)
.WithOne(p => p.ActionConfiguration)
.HasForeignKey(p => p.ActionConfigId)
.OnDelete(DeleteBehavior.Cascade);
}
}
}