sql-server - Entity Framework Core 中基于条件的外键
问题描述
我必须创建一个基于类之间一对多关系的条件。我有以下课程。
public enum Type
{
Type1,
Type2
}
public Class Base1
{
public int Id {get; set;}
public string Prop {get; set;}
public List<NProp> NProps {get; set;}
}
public Class Base2
{
public int Id {get; set;}
public string Prop {get; set;}
public List<NProp> NProps {get; set;}
}
public class NProp
{
public Type Type {get; set;}
public int BaseId {get; set;} //Foreign Key
public string NProp {get; set;}
}
现在,在 NProp 类中,有一个外键baseId
应该是Base1
if the Type
isType1
和Base2
if the Type
is的外键Type2
。首先,这可能吗?如果是,那么如何?
解决方案
不,这是不可能的。您应该使用两个 FK。每个基地一个。
推荐阅读
- javascript - 有人可以解释这个功能是如何工作的吗?函数{}(函数
- python - 如何退出while循环
- java - Spring Data Rest - 存储库继承创建奇怪的搜索端点
- reactjs - 在打字稿中使用带有反应钩子的反应上下文
- azure - Azure:在没有 VM 的情况下部署 Angular(前端)和节点(后端)应用程序
- excel - 使用 EPPlus 的 Excel 导出按钮
- batch-file - 从 CMD 运行批处理文件,打开 exe 并将字符串传递给 exe
- qlikview - 如何在 Qlikview 中将直接表值或表数据获取到变量中?
- node.js - NodeJS 和 MariaDB,等待查询结果
- angular - 角材料表内的内容投影