NHibernate where 用别名限制

NHibernate where restrictions with an alias

我正在尝试查询 where someProperty.contains(string) || otherProperty.contains(string) 所以我发现了以下内容:

.where(
 restrictions.on<type>(x => x.property).IsLike(string) ||
 restrictions.on<type>(x => x.prop2).IsLike(string)
)

但是,我在此之前有一个别名,用于连接的其中一个属性:

session.QueryOver<Trade>()
   .JoinAlias(x => x.TradeType, () => ttypeAlias)
   .Where(
       Restrictions.On<Trade>(c => c.Nickname).IsLike("%" + searchString + "%") ||
       Restrictions.On<TradeType>(() => ttypeAlias.TradeTypeName).IsLike("%" + searchString + "%") ||
   )

但我在别名的限制行上遇到错误:

delegate type does not accept 0 arguments

() => ttypeAlias.TradeTypeName

如何加入这个别名?

这是上面使用的.On()的语法:

/// <summary>
/// Build an ICriterion for the given property
/// </summary>
/// <param name="expression">lambda expression identifying property</param>
/// <returns>returns LambdaRestrictionBuilder</returns>
public static LambdaRestrictionBuilder On<T>(Expression<Func<T, object>> expression)
{
    ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(expression.Body);
    return new LambdaRestrictionBuilder(projection);
}

这给了我们答案:

passed expression must have one argument (which does not have to be used)

有效的语法可能是这样的:

// no argument - it is wrong
// Restrictions.On<TradeType>(() => ttypeAlias.TradeTypeName)...

// here we expect one argument, and naming his lo-dash - is convention to say
// it won't be used, it is there just to fulfill all the rules
Restrictions.On<TradeType>(_ => ttypeAlias.TradeTypeName)...