private ICriterion GetCollectionContainsCriteria(CollectionAccessExpression arg, Expression containsExpression) { EntityExpression rootEntity = EntityExpressionVisitor.FirstEntity(arg); var rootEntityType = rootEntity.Type; if (rootEntity.MetaData.HasProxy) { rootEntityType = rootEntity.MetaData.GetMappedClass(EntityMode.Poco); } DetachedCriteria query = DetachedCriteria.For(rootEntityType) .SetProjection(Projections.Id()); var visitor = new MemberNameVisitor(query.Adapt(session), true); visitor.Visit(arg); //TODO: this won't work for collections of values var containedEntity = QueryUtil.GetExpressionValue(containsExpression); var collectionIdPropertyName = visitor.MemberName + "." + arg.ElementExpression.MetaData.IdentifierPropertyName; var idValue = arg.ElementExpression.MetaData.GetIdentifier(containedEntity, EntityMode.Poco); query.Add(Restrictions.Eq(collectionIdPropertyName, idValue)); string identifierName = rootEntity.MetaData.IdentifierPropertyName; return(Subqueries.PropertyIn(identifierName, query)); }
private ICriterion GetCollectionContainsCriteria(Expression list, Expression containedExpr) { var values = QueryUtil.GetExpressionValue(list) as ICollection; if (values == null) { throw new InvalidOperationException("Expression argument must be of type ICollection."); } return(Restrictions.In(MemberNameVisitor.GetMemberName(rootCriteria, containedExpr), values)); }
protected override Expression VisitConstant(ConstantExpression expr) { Type = BinaryCriterionType.Value; Value = QueryUtil.GetExpressionValue(expr); return(expr); }
private ICriterion GetLikeCriteria(MethodCallExpression expr, MatchMode matchMode) { return(Restrictions.Like(MemberNameVisitor.GetMemberName(rootCriteria, expr.Object), String.Format("{0}", QueryUtil.GetExpressionValue(expr.Arguments[0])), matchMode)); }