c# - 如何在实体框架中定义非常规(?)一对多关系
问题描述
我需要使用一个有两个表的数据库,Proprietaires
并且Certification
.
Proprietaires
有这些列:
- ID
- 身份认证
- 姓名
- ...
Certification
有这些列:
- ID
- 业主编号
- 姓名
- ...
所以我这样定义我的Proprietaire
实体:
public class Proprietaire
{
public int Id { get; set; }
public int IdCertification { get; set; }
public string Name { get; set; }
public virtual ICollection<Certification> Certifications { get; private set; } = new List<Certification>();
}
和Certification
实体:
public class Certification
{
public int Id { get; set; }
public int ProprietaireId { get; set; }
public string Name { get; set; }
public virtual Proprietaire Proprietaire { get; set; }
}
我的问题是我不知道将关系定义为具有以下行为:
当我访问Proprietaire
我的实体的属性时Certification
,我需要获取Proprietaire
where Proprietaire.Id == Certification.ProprietaireId
。这部分有效。
但是当我访问Certifications
我的实体的(列表)属性时Proprietaire
,我需要获得所有的认证
where Certification.ProprietaireId == Proprietaire.IdCertification
我什至不知道EF是否可能。但是数据库的结构不是很好,但我需要处理它......
有解决办法吗?
谢谢
解决方案
推荐阅读
- express - 使用 graphql-yoga 使用 Next.js 清理 URL
- vue.js - 无法使用 vuex 实现 Search()
- tensorflow - 拟合生成器函数中的数据增强错误
- ansible - 带有字符串列表的 Ansible 构建列表字典
- python - 合并两个数据框时出错
- haskell - 未能 putStrLn 刚刚分配的东西
- python - 我正在尝试使用 pandas TimeGrouper 创建一些日期的频率表,但是它返回错误
- arrays - 比较后如何显示数组元素的位置?
- android - 在代码部分需要不同 API 的情况下,支持具有不同最低 API 级别的构建的最有效方法是什么
- regex - 如何从 `|` 到 `|` 进行选择?