Let's take as example these domain objects:
public class A
{
public Guid Id { get; set; }
public ICollection<B> CollectionOfB { get; set; }
}
public class B
{
public Guid Id { get; set; }
public string Name { get; set; }
}
I need to retrieve any A
object having a B
with these names name1
, name2
using NHibernate 3.x.
For example, imagine that you get which B
ones want to retrieve from an array of names as string string[] names = new string[] { "name1", "name2" }
.
I thought about .Query<A>().Where(someA => some.CollectionOfB.Any(someB => names.Contains(someB.Name)))
, and I doubt that this would be compiled as an SQL query by the NHibernate LINQ provider. maybe this would be compiled into a not very optimal SQL query.
What would be the optimal way of building this query using NHibernate 3.x LINQ provider?