自定义导航属性人口

时间:2018-07-18 04:09:34

标签: entity-framework ef-code-first navigation-properties

我有一个在Code-First中定义的表,如下所示;

public class Rule
{
    [Key]
    public Guid Id { get; private set; }
    public int RuleId { get; private set; }
    public int Version { get; private set; }
    // Some other properties that aren't relevant
    public virtual List<Rule> OtherVersions { get; private set; }
}

我希望OtherVersions是一个导航属性,因此如果我有一个Rule为1且RuleId为1的Version,{{1 }}将返回所有其他OtherVersions实例,这些实例的Rule也为1,但没有RuleId为1。

例如:

Version

很明显,我可以通过其他方式来做到这一点,但这意味着向现有查询中添加大量代码(即GetById,GetByName,Search等),如果可能的话,我不希望这样做

我怀疑我需要在| Id | RuleId | Version | |---------|---------|---------| | <guid1> | 1 | 1 | | <guid2> | 1 | 2 | | <guid3> | 2 | 1 |

中做类似的事情
OnModelCreating

但是我不太清楚正确的语法。在Google看来,我也看不出与我要找的结果类似的结果。

0 个答案:

没有答案
相关问题