문제

I'm trying, without successs, to create a query with QueryOver in NHibernate. The resulting SQL I need to get is the following:

select mn.Story_ID from Membership_Updates mn
join Updates upd on mn.Story_ID = upd.Story_ID
where mn.MembershipUser_ID = 1
group by mn.Story_ID having MAX(mn.DismissTime) <= MAX(upd.CreationDate)

My classes:

public class MembershipUpdates
{
  public MembershipUpdates()
  {
    DismissTime = DateTime.Now;
  }

  public virtual int Id  { get; set; }
  public virtual MembershipUser User { get; set; }
  public virtual Story Story { get; set; }
  public virtual DateTime DismissTime { get; set; }
}

public class Updates 
{
  public Updates()
  {
    CreationDate = DateTime.Now;
  }

  public virtual int Id  { get; set; }
  public virtual DateTime CreationDate { get; private set; }
  public virtual Story Story { get; set; }
  public virtual string Message{ get; set; }
}

Maybe I'm missing something obvious

도움이 되었습니까?

해결책

I might be wrong, but I don't think QueryOver allows you to join unrelated entities (without resorting to subqueries, that is).

I would use HQL for this:

select mn.Story
from MembershipUpdates mn, Updates upd
where upd.Story = upd.Story
and mn.User.id = 1
group by mn.Story
having MAX(mn.DismissTime) <= MAX(upd.CreationDate)

Sidenote: your entity class name should be singular.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top