private void HandleGroupBy(System.Linq.Expressions.MethodCallExpression m) { Select.PostfixSelectVisitor svst = new Select.PostfixSelectVisitor(row, s => NHEX.Projections.GroupProperty(s)); LambdaExpression lambda = (LambdaExpression)Linq.Utils.Expression.StripQuotes(m.Arguments[1]); Expression exp = svst.Visit(lambda.Body); //If there are no projection there is no more work to do. if (svst.ListOfProjections.Count == 0) { return; } Translation.projector = Expression.Lambda(exp, row); for (Int32 I = 0; I < svst.ListOfProjections.Count; ++I) { String projectedName = svst.ProjectionsPropertyNames[I]; projectedProperties.AddLast(projectedName); if (projectedName.Contains(".")) { rootCriteria.SetFetchMode(projectedName.Substring(0, projectedName.LastIndexOf('.')), FetchMode.Join); } Linq.Utils.NHibernate.AddProjectionToCriteria( NHEX.Projections.GroupProperty(projectedName), rootCriteria); } //The m.type is the return value, it is an IEnumerable<IGrouping<T, S>> //Linq.Utils.LinqGroupingResultTransformer transformer = // new NHibernate.Linq.Utils.LinqGroupingResultTransformer( // m.Type.GetGenericArguments()[0], svst.ProjectionsPropertyNames[0]); //rootCriteria.SetResultTransformer(transformer); }
/// <summary> /// Handle the select part of an expression. /// </summary> /// <param name="m"></param> private void HandleSelect(System.Linq.Expressions.MethodCallExpression m) { LambdaExpression lambda = (LambdaExpression)Linq.Utils.Expression.StripQuotes(m.Arguments[1]); Select.PostfixSelectVisitor svst = new Select.PostfixSelectVisitor(row, s => NHEX.Projections.Property(s)); Expression exp = svst.Visit(lambda.Body); //If there are no projection there is no more work to do. if (svst.ListOfProjections.Count == 0) { return; } Translation.projector = Expression.Lambda(exp, row); for (Int32 I = 0; I < svst.ListOfProjections.Count; ++I) { projectedProperties.AddLast(svst.ProjectionsPropertyNames[I]); Linq.Utils.NHibernate.AddProjectionToCriteria( svst.ListOfProjections[I], rootCriteria); } }