I have simple classes:
public class Order
{
public int Id {get;set;}
public IList<Name> Names{get;set;}
}
public class Name
{
public int Id {get;set;}
public int LangId {get;set;}
public string LocalName {get;set;}
}
The quesetion is how to query subcollection of Order to get all that have some Order.Names.LocalName (something like this):
IList<Order> orders = repository.GetByProductLocalName("laptop");
I would like to use new NH3 feature QueryOver, not using Linq (I'v found some solutions in SO but all of them uses Linq).
All you need to do is declare an alias variable for the Names collection and then you can use that in the where clause...
String localName = "laptop";
Name namesAlias = null;
return session.QueryOver<Order>()
.JoinAlias(x => x.Names, () => namesAlias)
.Where(() => namesAlias.LocalName == localName)
.TransformUsing(Transformers.DistinctRootEntity)
.List<Order>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With