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

80 lines
1.8 KiB
Markdown
Raw Normal View History

# tx_software 维度表
> 所属模块:[数据模型概览](../概览.md)
---
## 1. 表定义
**表名**`tx_software`
**描述**TX软件版本维度表存储所有软件版本号hex版本
---
## 2. 字段定义
| 列名 | 类型 | 约束 | 说明 |
|------|------|------|------|
| id | UUID | PK, NOT NULL | 主键,自动生成 |
| version | VARCHAR(50) | UNIQUE, NOT NULL | 软件版本号hex版本 |
| is_deleted | BOOLEAN | NOT NULL, DEFAULT FALSE | 软删除标记 |
| created_at | TIMESTAMP | NOT NULL, DEFAULT NOW() | 创建时间 |
---
## 3. EF Core 模型
```csharp
// Models/TxSoftware.cs
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WCTDataMiner.Models;
[Table("tx_software")]
public class TxSoftware
{
[Key]
[Column("id")]
public Guid Id { get; set; } = Guid.NewGuid();
[Required]
[MaxLength(50)]
[Column("version")]
public string Version { get; set; } = null!;
[Required]
[Column("is_deleted")]
public bool IsDeleted { get; set; } = false;
[Required]
[Column("created_at")]
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
// Navigation Properties
public ICollection<TestScenario> TestScenarios { get; set; } = [];
}
```
---
## 4. 使用说明
软件版本在解析文件名时自动创建,无需预置数据:
```csharp
// 获取或创建软件版本
public async Task<TxSoftware> GetOrCreateAsync(string version)
{
var existing = await context.TxSoftwares
.FirstOrDefaultAsync(s => s.Version == version);
if (existing != null) return existing;
var newSoftware = new TxSoftware { Version = version };
context.TxSoftwares.Add(newSoftware);
await context.SaveChangesAsync();
return newSoftware;
}
```