1 回答
TA贡献1842条经验 获得超21个赞
您需要自定义实现SubqueryExpression来实现它:
/// <summary>
/// A comparison between multiple properties in the outer query and the
/// result of a subquery
/// Note: DB support of row value constructor is required
/// </summary>
[Serializable]
public class MultiPropertiesSubqueryExpression : SubqueryExpression
{
private readonly string[] _propertyNames;
public MultiPropertiesSubqueryExpression(string[] propertyNames, string op, DetachedCriteria dc)
: base(op, null, dc)
{
_propertyNames = propertyNames;
}
protected override SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return new SqlString("(", string.Join(", ", _propertyNames.Select(pn => criteriaQuery.GetColumns(criteria, pn)).SelectMany(x => x)), ")");
}
}
以及用法示例:
DetachedCriteria detachedCriteria = DetachedCriteria.For(typeof(Bar))
//.Add(...) //Add some conditions
.SetProjection(Projections.ProjectionList().Add(Property.ForName("Prop1")).Add(Property.ForName("Prop2")));
var result = session.CreateCriteria(typeof(Foo))
.Add(new MultiPropertiesSubqueryExpression(new[] {"Prop1", "Prop2"}, "in", detachedCriteria))
.List<Foo>();
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报