1 回答

TA貢獻1842條經(jīng)驗 獲得超21個贊
您需要自定義實現(xiàn)SubqueryExpression來實現(xiàn)它:
/// <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 關(guān)注
- 154 瀏覽
添加回答
舉報