首页 > 解决方案 > 使用复杂类型的策略

问题描述

我已经阅读了有关拥有类型和值转换的内容(截至 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。这种方法可以吗?或者你推荐我使用哪种方法?

标签: c#entity-framework-core

解决方案


推荐阅读