让我们以这些域对象为例:
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; }
}
我需要使用 NHibernate 3.x检索具有这些名称的任何A
对象B
name1
name2
。
例如,假设您B
从名称数组中获取要检索的字符串作为字符串string[] names = new string[] { "name1", "name2" }
。
我想过.Query<A>().Where(someA => some.CollectionOfB.Any(someB => names.Contains(someB.Name)))
,我怀疑这会被 NHibernate LINQ 提供程序编译为 SQL 查询。也许这会被编译成一个不是很优化的 SQL 查询。
使用 NHibernate 3.x LINQ 提供程序构建此查询的最佳方式是什么?