2

Given entities like these:

public class Entity
{
    public int Id { get; set; }
    public ICollection<EntityTwo> EntityTwos { get; set; }
}

public class EntityTwo
{
    public int Id { get; set; }
    public int TypeId { get; set; }
    public int EntityId { get; set; }
}

Normally, Entity.EntityTwos would return all EntityTwo entities where EntityId equals Entity.Id. Is it possible to rig up the model so that property returns entities that join on that Id, but also have EntityTwo.TypeId == 2 (essentially adding a where clause to the join)?

4

2 回答 2

1

您必须进行手动连接,而不是依赖导航属性来创建隐含连接。

于 2012-09-06T21:59:01.750 回答
0

也许你可以通过不同的方式来解决这个问题。您的加入密钥将是:

{ TypeId, Id } equals { 2, Id }

也许可以使用常量作为两个复合键之一?将 Ladislav 的 复合键视为外键答案。

于 2012-09-06T21:43:22.610 回答