EF5流畅的API一对一没有导航 [英] EF5 Fluent API one-to-one without navigator

查看:180
本文介绍了EF5流畅的API一对一没有导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我想要做的是像

 表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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆