【问题标题】:EF5 Fluent API one-to-one without navigatorEF5 Fluent API 一对一无需导航器
【发布时间】:2013-02-20 10:48:08
【问题描述】:

在 Fluent API EF5 中,是否可以通过 Join 表配置一对一关系(如果是个好主意,但不确定)?我不需要从右到左的导航,只需从左到右即可。

我想做的就是这样

Table A1
TableA1_ID  //Key
RankValue   //int


Table A1_Rank (join table)
TableA1_ID
RankId

Table Rank
RankId
Value

POCO

public class A1 
{
    public int Id { get; set; }
    public decimal RankValue { get; set; }
    public virtual Rank Rank { get; set; }
}

public class Rank
{
    public int RankId { get; set; }
    public decimal Value { get, set; }
    public decimal Hits { get; set; }
}

A1.RankValue 是我需要在存储库中计算的字段,不是来自数据库,使用 Rank.Value 和 Rank.Hits(而 Rank.Value 显然包含当前排名值)。

我在 A1 配置中尝试过这个,但这会创建一个从 Rank 到 A1 的 FK,这不是我需要的。

  HasRequired(e => e.Rank)
    .WithRequiredPrincipal()
    .WillCascadeOnDelete(true);

【问题讨论】:

    标签: c# entity-framework entity-framework-5 one-to-one


    【解决方案1】:

    我解决了将 RankId 列添加到 A1 的问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 2012-12-01
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 1970-01-01
    相关资源
    最近更新 更多