EF5流畅的API一对一没有导航 [英] EF5 Fluent API one-to-one without navigator
问题描述
我想要做的是像
表A1
TableA1_ID //键
RankValue // int
表A1_Rank (连接表)
TableA1_ID
RankId
表排名
RankId
值
POCO
公共类A1
{
public int Id {get;组; }
public decimal RankValue {get;组; }
public virtual Rank Rank {get;组; }
}
public class Rank
{
public int RankId {get;组; }
public decimal值{get,set; }
public decimal Hits {get;组; }
}
A1.RankValue是一个我需要在仓库中计算的字段,不是来自数据库,使用Rank.Value和Rank.Hits(而Rank.Value显然包含当前的排名值)。
我试过这个,在A1配置中,但是这会创造一个从等级到A1的FK,而不是我所需要的。
HasRequired(e =>排名)
.WithRequiredPrincipal()
.WillCascadeOnDelete(true);
我解决了将RankId列添加到A1。 p>
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);
I solved adding the RankId column to A1.
这篇关于EF5流畅的API一对一没有导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!