private IList <T> GetElementList(MethodCallExpression call, int count) { if (call.Arguments.Count > 1) { rootCriteria.Add(WhereArgumentsVisitor.GetCriterion(rootCriteria, session, call.Arguments[1])); } return(rootCriteria.SetFirstResult(0).SetMaxResults(count).List <T>()); }
private T HandleAnyCall(MethodCallExpression call) { rootCriteria.SetProjection(Projections.RowCount()); if (call.Arguments.Count > 1) { rootCriteria.Add(WhereArgumentsVisitor.GetCriterion(rootCriteria, session, call.Arguments[1])); } int count = (int)rootCriteria.UniqueResult(); //HACK: the Any method always returns bool - maybe need to make this class non-generic return((T)(object)(count > 0)); }
private Expression VisitCriterionExpression(Expression expr) { IEnumerable <ICriterion> criterion = WhereArgumentsVisitor.GetCriterion(_rootCriteria, _session, expr); if (criterion.Count() > 0) { Conjunction conjunction = new Conjunction(); foreach (ICriterion crit in criterion) { conjunction.Add(crit); } _projections.Add(Projections.Conditional( conjunction, Projections.Constant(true), Projections.Constant(false)) ); } return(expr); }
protected override Expression VisitMethodCall(MethodCallExpression expr) { if (WhereArgumentsVisitor.SupportsMethod(expr.Method.Name)) { return(VisitCriterionExpression(expr)); } //TODO: this needs to be refactored... //create any collection subcriteria and get the collection access expression MemberNameVisitor memberVisitor = new MemberNameVisitor(_rootCriteria, true); memberVisitor.Visit(expr.Arguments[0]); CollectionAccessExpression collectionExpr = (CollectionAccessExpression)memberVisitor.CurrentExpression; string propertyName = null; IProjection projection = null; PropertyProjection currentProjection; if (expr.Arguments.Count > 1) { propertyName = MemberNameVisitor.GetMemberName(_rootCriteria, expr.Arguments[1]); } else if ((currentProjection = _rootCriteria.GetProjection() as PropertyProjection) != null) { propertyName = currentProjection.PropertyName; } switch (expr.Method.Name) { case "Average": projection = NHProjections.Avg(propertyName); break; case "Count": case "LongCount": if (expr.Arguments.Count > 1) { _rootCriteria.Add(WhereArgumentsVisitor.GetCriterion(_rootCriteria, _session, expr.Arguments[1])); } if (collectionExpr != null) { //get count on collection element's identifier property propertyName = memberVisitor.MemberName + "." + collectionExpr.ElementExpression.MetaData.IdentifierPropertyName; projection = NHProjections.Count(propertyName); } else { projection = NHProjections.RowCount(); } break; case "Max": projection = NHProjections.Max(propertyName); break; case "Min": projection = NHProjections.Min(propertyName); break; case "Sum": projection = NHProjections.Sum(propertyName); break; default: throw new NotImplementedException("The method '" + expr.Method.Name + "' is not implemented."); } _projections.Add(projection); return(expr); }
private void HandleWhereCall(MethodCallExpression call) { IEnumerable <ICriterion> criterion = WhereArgumentsVisitor.GetCriterion(rootCriteria, session, call.Arguments[1]); rootCriteria.Add(criterion); }