Hi NeoDarque, it works very fine, thank you so much man! Just one more
question, look my final result (question in bold)
var subQuery = Session.QueryOver<Laudo>()
.Where(x => /* conditions here */)
.OrderBy(x => x.Numero).Desc
.Select(Projections.Property<Laudo>(x => x.Numero))*.Take(4)
*;
AnaliseInfo analiseInfo = null;
Analise analise = null;
CampoAnalise campoAnalise = null;
CampoInfo campoInfo = null;
var query = Session.QueryOver(() => analiseInfo)
.Inner.JoinAlias(() => analiseInfo.Analise, () => analise)
.Left.JoinAlias(() => analiseInfo.Campos, () => campoInfo)
.Left.JoinAlias(() => campoInfo.Campo, () => campoAnalise)
.WithSubquery.WhereProperty(x =>
x.NumeroLaudo).In(*(QueryOver<Laudo>)
subQuery*)
.OrderBy(() => analiseInfo.DataAnalise).Desc
.TransformUsing(Transformers.DistinctRootEntity);
I need only 4 records on the subQuery (4 numbers.. it is not the ID
property) and if I try without .Take(4) method, it works fine but with it I
got a exception saying that it is not possible to use limit in the IN
operator (MySql Exception....).
Another thing is, I need to cast on the .In(QueryOver<U> subQuery) method
to QueryOver<U>? I'm saying it because the first query returns a
IQueryOver<T, T>.
I prefer using QueryOver, I have using Linq because I'm begining with
NHibernate and I'm learning! (Sorry for the code, it's pt-BR).
Thank you for your help.
On Wed, Jul 18, 2012 at 7:36 PM, NeoDarque <[email protected]> wrote:
> How about if you do it all with QueryOver, since I believe it's still not
> possible to do subqueries using the linq provider, but I could be
> mistaken...
>
> So perhaps something like this:
>
> var subQuery = QueryOver.Of<Category>()
> .Where(c => /* condition here */ && /* another
> condition here */ && /* another condition here too */)
> .Select(Projections.Id());
>
> Product productAlias = null;
> Supplier supplierAlias = null;
> Order orderAlias = null;
> OrderRow orderRowAlias = null;
>
> var result = Session.QueryOver(() => productAlias)
> .Left.JoinAlias(() => productAlias.Supplier, () =>
> supplierAlias)
> .Left.JoinAlias(() => productAlias.Order, () =>
> orderAlias)
> .Left.JoinAlias(() => orderAlias.OrderRow, () =>
> orderRowAlias)
> .WithSubquery.WhereProperty(() => productAlias.Category
> .Id).In(subQuery)
> .OrderBy(() => productAlias.Name).Desc
> .TransformUsing(Transformers.DistinctRootEntity)
> .List();
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nhusers/-/v2l6mLTNlsQJ.
>
> 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/nhusers?hl=en.
>
--
______________________________________
Felipe B. Oriani
felipeoriani.com.br [email protected]
@felipeoriani<http://www.twitter.com/felipeoriani>
LinkedIn <http://br.linkedin.com/in/felipeoriani>
Facebook<http://www.facebook.com/felipeoriani>
Contato: (19) 9611-8646 / (19) 3421-7850
"...Trabalhe quanto puder, tornando-se útil quanto possível..." , por André
Luiz
--
You received this message because you are subscribed to the Google Groups
"nhusers" 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/nhusers?hl=en.