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?
I've tried this so far, but it doesn't work.
string queryString =
"SELECT p.Id " +
"FROM ProgramParticipation p " +
"LEFT OUTER JOIN p.GeneratedEvents ge " +
"WHERE p.IsActive = :isActive " +
"AND p.StartDateOfParticipation < :startedBeforeDate "
+
"AND p.EndDateOfParticipation > :now " +
"AND ge.TypeOfEvent.Code = :code " +
"GROUP BY p.Id " +
"HAVING COUNT(ge.Id) = 0";
SimpleQuery<int> query =
new SimpleQuery<int>(
typeof(ProgramParticipation), queryString);
query.SetParameter("startedBeforeDate", startedBeforeDate);
query.SetParameter("now", now);
query.SetParameter("code", eventCode);
query.SetParameter("isActive", true);
return query.Execute();
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.