gpt4 book ai didi

c# - NHibernate where 用别名限制

转载 作者:太空宇宙 更新时间:2023-11-03 23:24:13 25 4
gpt4 key购买 nike

我正在尝试查询 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)...

关于c# - NHibernate where 用别名限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34346760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com