dotnetcore / dotnetcore/FreeSql

如何优雅的实现字典管理

Open
#1,997 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.4k
Forks
910
PR merge metrics
No merged PRs in 30d

Description

现在后台系统都需会有字典管理功能, 其实就一张KV大表, 放了很多值用type做区分,
有没优雅的视实现的方式, 可以映射 不同的类型到这个大表?
#### Feature 特性

```c#
public class Dictionary
{//通用配置表 , 实际建表
public string Id{get;set;}
public string A{get;set;}
public string B{get;set;}
public string C{get;set;}
public string D{get;set;}
public string Type{get;set;}
}
```

#### 简要描述原因

```c#
[Map(typeof(Dictionary), where:"type=ConfigA")]
public class ConfigA
{// 类映射到Dictionary , 不建表, 有点像导航属性
public string Id{get;set;}

[Map("A")]
public string A1{get;set;}
[Map("B")]
public string B1{get;set;}
[Map("C")]
public string C1{get;set;}
}
```
类似这样, 就把 ConfigA 映射到 Dictionary , 通过type=ConfigA进行过滤, 字段也进行了映射, 可以进行crud, 最终操作还是Dictionary的操作
#### 使用场景
这样就非常方便优雅
```c#
// c# code
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.