private static Func <string, T> ProjectNew <T>(NewExpression nex, QueryParts parts, SubqueryParts subquery) { var results = new Dictionary <Expression, Func <object, object> >(); var list = new List <Func <object, object> >(); foreach (var s in subquery.Selects) { var factory = QuerySourceConverterFactory.CreateResult(s.Name, s.ItemType, s.QuerySource, parts); if (s.Expression == null) { throw new FrameworkException("Null expression!?"); } results[s.Expression] = factory.Instancer; list.Add(factory.Instancer); } var arguments = new object[nex.Arguments.Count]; Func <string, T> result = value => { if (value == null) { return(default(T)); } var items = PostgresRecordConverter.ParseRecord(value); for (int i = 0; i < items.Length; i++) { arguments[i] = list[i](items[i]); } return((T)nex.Constructor.Invoke(arguments)); }; return(result); }
public static SelectSubqueryData Create(QueryParts parts, SubqueryParts subquery) { Contract.Requires(parts != null); Contract.Requires(subquery != null); var selects = new List <KeyValuePair <IQuerySource, Func <object, object> > >(); foreach (var s in subquery.Selects) { var factory = QuerySourceConverterFactory.Create(s.QuerySource, parts); selects.Add(new KeyValuePair <IQuerySource, Func <object, object> >(factory.QuerySource, factory.Instancer)); } return(new SelectSubqueryData(selects)); }