Files
WCTDataMiner/docs/data-model/entities/TxHardware维度.md

105 lines
2.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# tx_hardware 维度表
> 所属模块:[数据模型概览](../概览.md)
---
## 1. 表定义
**表名**`tx_hardware`
**描述**TX硬件版本维度表存储所有硬件版本号
---
## 2. 字段定义
| 列名 | 类型 | 约束 | 说明 |
|------|------|------|------|
| id | UUID | PK, NOT NULL | 主键,自动生成 |
| version | VARCHAR(50) | UNIQUE, NOT NULL | 硬件版本号 |
| is_deleted | BOOLEAN | NOT NULL, DEFAULT FALSE | 软删除标记 |
| created_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | 创建时间 |
---
## 3. EF Core 模型
### 实体类
```csharp
// Models/TxHardware.cs
namespace WCTDataMiner.Models;
public class TxHardware
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Version { get; set; } = null!;
public bool IsDeleted { get; set; } = false;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
// Navigation Properties
public ICollection<TestScenario> TestScenarios { get; set; } = [];
}
```
### 配置类
```csharp
// Data/Configurations/TxHardwareConfiguration.cs
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WCTDataMiner.Models;
namespace WCTDataMiner.Data.Configurations;
public class TxHardwareConfiguration : IEntityTypeConfiguration<TxHardware>
{
public void Configure(EntityTypeBuilder<TxHardware> builder)
{
builder.ToTable("tx_hardware");
builder.HasKey(e => e.Id);
builder.Property(e => e.Id).HasColumnName("id");
builder.Property(e => e.Version)
.IsRequired()
.HasMaxLength(50)
.HasColumnName("version");
builder.Property(e => e.IsDeleted)
.IsRequired()
.HasDefaultValue(false)
.HasColumnName("is_deleted");
builder.Property(e => e.CreatedAt)
.IsRequired()
.HasDefaultValueSql("NOW()")
.HasColumnName("created_at");
builder.HasIndex(e => e.Version).IsUnique();
}
}
```
---
## 4. 使用说明
硬件版本在解析文件名时自动创建,无需预置数据:
```csharp
// 获取或创建硬件版本
public async Task<TxHardware> GetOrCreateAsync(string version)
{
var existing = await context.TxHardwares
.FirstOrDefaultAsync(h => h.Version == version);
if (existing != null) return existing;
var newHardware = new TxHardware { Version = version };
context.TxHardwares.Add(newHardware);
await context.SaveChangesAsync();
return newHardware;
}
```