EF5 Fluent API one-to-one without navigator

2019-08-19 08:22发布

问题:

In Fluent API, EF5, is possibile to configure a One-To-One relationship, through a Join table (if is a good idea, not sure about that)? I don't need a navigation from right to left, just from left to right.

What I'm trying to do is something like that

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 is a field that I need to calculate in the repository, is not coming from db, using Rank.Value and Rank.Hits (while Rank.Value obviously contains the current ranking value).

I tried this, in A1 configuration, but this creates a FK from Rank to A1 and it isn't what I need.

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

回答1:

I solved adding the RankId column to A1.