c# - 使用复杂类型的策略
问题描述
我已经阅读了有关拥有类型和值转换的内容(截至 2.1 版)。但我的情况是这样的,我有很多实体具有一个或多个具有静态值的属性,例如:
public class Entity
{
public Gender Gender {get;set;};
}
public enum Gender
{
Male,
Female
}
这适用于将从外部网站使用的 Web api。因此,对于那些复杂类型,无法获取字符串标识符来构建下拉列表或类似的东西。所以我考虑创建一个表来存储所有静态类型,如下所示:
public class RefType
{
public int RefTypeId { get; set; }
public string GroupName { get; set; }
public int Key { get; set; }
public string Value { get; set; }
}
public class Entity
{
public RefType Gender {get;set;}
public RefType Type {get;set;}
}
并且应用程序域中的每个实体都将对该表具有非限制性 FK。这种方法可以吗?或者你推荐我使用哪种方法?
解决方案
推荐阅读
- java - 在 CentOS 7 上无法确认 java 6 的版本
- html - 有没有办法在谷歌中搜索 html 元素,或者有什么方法可以在不传递 URL 的情况下找出元素?
- javascript - MVC 从 TextBoxFor 值 onbuttonclick 填充 Textboxfor
- wordpress - 列出所有自定义帖子类型中的所有帖子标题与组,排除一些
- python - 如何使用 Google Photo API 更新视频的创建时间
- apache-spark - Pyspark:数据帧中每个 id 的最后一个非空记录(Spark Streaming)
- combinatorics - 生成所有“无替换”子集系列
- angular - Angular 5 - 具有两个空父路由的路由器
- javascript - ipad html5 网络应用程序 - 无法在按钮上单击两次
- ios - 什么是超级视网膜显示器?