1

A "case" can have many action types and each action is logged in a journal. I want to show a list of "cases" only with the latest journal entry

This is the T-SQL sub query

SELECT SagId, max(Dato) as maxdate FROM vOpgaveliste o group by SagId

And this is the T-SQL main query

select o.* from
(
SELECT SagId, max(Dato) as maxdate
FROM vOpgaveliste o
group by SagId
)
as nyeste
join vOpgaveliste o on o.SagId = nyeste.SagId and o.Dato = nyeste.maxdate

I can create the subquery in linq

var queryInner = from o in query
                 where o.SagsbehandlerInit == "chr"
                 where o.Dato >= DateTime.Today && o.Dato <= DateTime.Today.AddDays(-7)
                 group o by o.SagId
                 into g
                 select new { SagId = g.Key, MaxDate = g.Max(d => d.Dato) };

I then created this query

  var outer = from o in query
              from s in queryInner
              where s.SagId == o.SagId && s.MaxDate == o.Dato    
              select o;

But NHibernate throws a System.NotSupportedException was unhandled by user code exception I also tried this syntax https://stackoverflow.com/a/16918106/1147577 but get an syntax error on the join statement

Thanks

Community
  • 1
  • 1
Martin Andersen
  • 2,460
  • 2
  • 38
  • 66

1 Answers1

0

NHibernate simply does not support sub queries within from statement block. It only supports it in the Select and Where block.

I guess you have to figure out another way to get your result.

Of course the linq to object or many other linq providers support all kind of crazy query constructs, the linq to Nhibernate implementation simply has tons of limitations.

MichaC
  • 13,104
  • 2
  • 44
  • 56