当值不在连接表中时选择
我有两个实体(实体是简单的):
Participation
[ActiveRecord]
public class Participation
{
[PrimaryKey]
public int Id {get;set;}
[HasMany(...)]
public IList<ParticipationEvent> GeneratedEvents {get;set;}
}
和 ParticipationEvent,
[ActiveRecord]
public class ParticipationEvent
{
[PrimaryKey]
public int Id {get;set;}
[BelongsTo]
public ProgramParticipation {get;set;}
[Property]
public int Code {get;set;}
}
其中(如您所见)一个 Participation 有许多事件。每个事件都有一个唯一的代码。
我想要的是选择所有没有特定事件的参与。我怎样才能用 NHibernate 做到这一点?我知道我可以使用 INNER JOIN 轻松获取具有特定事件的所有实例,但这可以反过来完成吗?
I have two Entities (the entities are simplefied):
Participation
[ActiveRecord]
public class Participation
{
[PrimaryKey]
public int Id {get;set;}
[HasMany(...)]
public IList<ParticipationEvent> GeneratedEvents {get;set;}
}
And ParticipationEvent
[ActiveRecord]
public class ParticipationEvent
{
[PrimaryKey]
public int Id {get;set;}
[BelongsTo]
public ProgramParticipation {get;set;}
[Property]
public int Code {get;set;}
}
where (as you can see) a Participation has many Events. Each event has a unique code.
What I want, is to select all Participations, that DOESN'T have a particular event. How can I do this with NHibernate? I know I can use a INNER JOIN to easily get all instances WITH a certain event, but can this be done the other way around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hibernate/NHibernate 支持 LEFT OUTER JOIN,它选择表 A 中连接到表 B 的所有记录,即使 B 没有对应的记录。要获取 A 中 B 中没有的记录,只需添加 WHERE tableB.SoleNonNullableColumn IS NULL 即可。不可为 null 的列可以为 null 的唯一原因是因为 LEFT OUTER JOIN 中的一行,其中 tableB 根本不显示。
Hibernate/NHibernate support a LEFT OUTER JOIN, which selects all records in table A joined to table B, even if B doesn't have a counterpart. To get those records in A that are not in B, simply add WHERE tableB.SoleNonNullableColumn IS NULL. The only way a non-nullable column can be null is because of a row in a LEFT OUTER JOIN, where tableB doesn't show up at all.